import java.util.Scanner;
//TIP To Run code, press or
// click the icon in the gutter.
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int min = Integer.MAX_VALUE;
int count = 0;
int[][] arr = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
arr[i][j] = sc.nextInt();
count+=arr[i][j];
if (!(i == 0 && j == 0) && !(i == N -1 && j == M - 1)) {
min = min > arr[i][j] ? arr[i][j] : min;
}
}
}
if (N % 2 == 0 && M % 2 == 0) {
count -= min;
}
System.out.println(count);
}
}