#include <bits/stdc++.h>
#define here cerr<<"==========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define ll long long
#define endl '\n'
#define sz(a) (ll)(a.size())
#define fi first
#define sc second
#define pll pair<ll,ll>
#define llinf 1000000000LL
#define pb push_back
using namespace std;
#define maxn 3010
#define lg 31
ll n,m;
ll a[maxn][maxn];
vector<pll> v[maxn];
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cerr.tie(0);
    cin >> n >> m;
    for(ll i = 1;i<=n;i++) for(ll j = 1;j<=m;j++) cin >> a[i][j];
    for(ll i = 1;i<=n;i++) for(ll j = 1;j<=m;j++) v[i+j].pb({i,j});
    ll sum = 0,ans = 0;
    for(ll k = 0;k<lg;k++){
        ll curans = llinf;
        //here;
        //dbg(k);
        for(ll e = 0;e<=1;e++){
            ll cur = 0;
            for(ll d = 2;d<=n+m;d++){
                ll sum = 0;
                for(pll p : v[d]){
                    ll x = p.fi,y = p.sc;
                    if((1<<k)&a[x][y]){
                        sum++;
                    }
                }
                //cerr<<"d: "<<d<< " "<<sum<<endl;
                sum&=1;
                if(sum!=e) cur++;
            }
            //dbg(cur);
            curans = min(curans,cur);
        }
        ans+=(1<<k)*curans;
    }
    cout<<ans<<endl;
    return 0;
}