#include using namespace std; #define rep(i, a, b) for (int i=a;i<(b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; int main() { cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; int sum = 0; int black = numeric_limits::max(); vvi G(N, vi(M)); for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { int curr; cin >> curr; G[i][j] = curr; sum += curr; if((i+j) % 2 == 1) black = min(black, curr); } } if(N % 2 == 0 and M % 2 == 0) { cout << sum - black << endl; } else cout << sum << endl; }