import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; import java.util.TreeSet; //TIP To Run code, press or // click the icon in the gutter. public class Main { static int[] dp; public static void main(String[] args) { //TIP Press with your caret at the highlighted text // to see how IntelliJ IDEA suggests fixing it. Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c = sc.nextInt(); long sum = 0; long min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < c; j++) { int l = sc.nextInt(); sum += l; if (min > l && !((i + j) % 2 == 0)) { min = l; } } } if (n % 2 == 0 && c % 2 == 0) { sum -= min; } System.out.println(sum ); // // String string = sc.next(); // uuuu(string, ""); // System.out.println(); } // static TreeSet kombinacie = new TreeSet<>(); // public static void uuuu(String posibilieties, String current) // { // if (posibilieties.isEmpty() && !kombinacie.contains(current)) { // kombinacie.add(current); // return; // } // for (int i = 0; i < posibilieties.length(); i++) { // String ss = posibilieties.charAt(0) + ""; // current += ss; // posibilieties = posibilieties.substring(1); // uuuu(posibilieties, current); // posibilieties = posibilieties + current; // current = current.substring(0, current.length() - 1); // } // } public static int findThoughtput(int i) { int [] array = dp; int max = Math.min(array[0], array[1]) + Math.min(array[3], array[4]); int abrez = Math.max(0, array[1] - array[0]); int derez = Math.max(0, array[4] - array[3]); int abvolne = Math.max(0, array[0] - array[1]); int devolne = Math.max(0, array[3] - array[4]); max += Math.max(Math.min(Math.min(abrez, devolne), array[2]), Math.min(Math.min(derez, abvolne), array[2])); return max; } }