#include <bits/stdc++.h> using namespace std; #define For(i, a, n) for(int i =a;i<n;i++) #define endl '\n' #define vec vector typedef long long ll; typedef pair<ll, ll> pii; template<typename... Args> void dbg(Args&&... args){ ((cerr<<args<<" |"),...); cerr<<endl; } template<class A, class B> pair<A, B> operator+(const pair<A, B>&a, const pair<A, B>& b){ return {a.first +b.first, a.second + b.second}; } template<class A, class B> ostream& operator<< (ostream& os, const pair<A, B>& a){ return os<<"("<<a.first<<", "<<a.second<<")"; } template<class A, class B, class C> basic_ostream<A, B>& operator<<(basic_ostream<A, B>& os, const C&c){ for(auto it=begin(c); it!=end(c);++it){ os<<(it==begin(c)?"":" ")<<*it; } return os; } void solve(){ int n, m;cin>>n>>m; ll sum = 0; ll male = 123124312312; For(i, 0, n){ For(j, 0, m){ ll a;cin>>a; sum += a; if((i+j)%2==1){ male =min(male, a); } } } dbg(male); if(n%2||m%2)cout<<sum<<endl; else cout<<sum - male<<endl; } main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int t=1;//cin>>t; while(t--){ solve(); } }