#include using namespace std; using ll = long long; int arr[1000][1000]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; ll s = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cin >> arr[i][j]; s += arr[i][j]; } } if((n & 1) || (m & 1)) { cout << s << '\n'; return 0; } ll mn = 10000000000ll; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { if((i+j) & 1) mn = min((ll)arr[i][j], mn); } } cout << s - mn << '\n'; return 0; }