#include <bits/stdc++.h>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define pb push_back
#define xx first
#define yy second


using namespace std;
typedef long long ll;

int n,m;
vector<int> dijag[3005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    ff(i,0,n - 1){
        ff(j,0,m - 1){
            int x;
            cin >> x;
            dijag[i+j].pb(x);
        }
    }

    ll suma = 0;

    ff(j,0,30){
        ll par = 0;
        ll nepar = 0;
        ff(i,0,n+m-2){
            int kol = 0;
            for(auto c:dijag[i]){
                if((1<<j)&c){
                    kol++;
                }
            }
            if(kol%2 == 0)par++;
            else nepar++;
        }
        ll koji = (1<<j);
        suma += (min(par,nepar)*koji);
    }
    cout << suma << "\n";

    return 0;
}