#include using namespace std; typedef long long ll; typedef double ld; int main() { int n, m; cin >> n >> m; vector> p(n, vector(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> p[i][j]; } } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans += p[i][j]; } } if ((n % 2 == 1) or (m & 2 == 1)) { cout << ans << endl; } else { ll min = 99999999; for (int i = 1; i < m; i++) { if (p[0][i] < min) min = p[0][i]; } if (m > 2) { for (int i = 0; i < m; i++) { if (p[1][i] < min) min = p[1][i]; } for (int i = 0; i < m; i++) { if (p[n - 2][i] < min) min = p[n - 2][i]; } } for (int i = 0; i < m - 1; i++) { if (p[n - 1][i] < min) min = p[n - 1][i]; } /////// for (int i = 1; i < n; i++) { if (p[i][0] < min) min = p[i][0]; } if (n > 2) { for (int i = 0; i < n; i++) { if (p[i][1] < min) min = p[i][1]; } for (int i = 0; i < n; i++) { if (p[i][m - 2] < min) min = p[i][m - 2]; } } for (int i = 0; i < n - 1; i++) { if (p[i][m - 2] < min) min = p[i][m - 1]; } cout << ans - min << endl; } return 0; }