// // Created by cteam37 on 10/19/24. // #include #include using namespace std; int main() { int n,m; cin >> n; cin >> m; ::uint64_t totalSum = 0; int min = INT32_MAX; for (int i = 0; i < n*m; ++i) { int val; cin >> val; totalSum += val; if(i == 0 || i == n*m - 1) { continue; } if (val < min) min = val; } if(n%2 == 0 && m%2 == 0) { cout << totalSum - min << endl; } else { cout << totalSum << endl; } return 0; }