// // Created by cteam37 on 10/19/24. // #include #include using namespace std; int main() { int n,m; cin >> n; cin >> m; int totalSum = 0; vector> fields; for (int row = 0; row < n; ++row) { fields.push_back({}); for (int col = 0; col < m; ++col) { int val; cin >> val; fields[row].push_back(val); totalSum += val; } } if(n%2 == 0 && m%2 == 0) { int32_t min = INT32_MAX; for (int row = 0; row < n-1; ++row) { int sum = 0; for (int col = 1; col < m; ++col) { sum += fields[row][col]; } if(sum < min) min = sum; } for (int row = 1; row < n; ++row) { int sum = 0; for (int col = 0; col < m-1; ++col) { sum += fields[row][col]; } if(sum < min) min = sum; } for (int col = 0; col < m-1; ++col) { int sum = 0; for (int row = 1; row < n; ++row) { sum += fields[row][col]; } if(sum < min) min = sum; } for (int col = 1; col < m; ++col) { int sum = 0; for (int row = 0; row < n-1; ++row) { sum += fields[row][col]; } if(sum < min) min = sum; } cout << totalSum - min << endl; } else { cout << totalSum << endl; } return 0; }