#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define nl '\n'
#define sp ' '

using namespace std;

ll ans = 0;

const int mxN = 1510;
int mat[mxN][mxN];
int n,m;

bool div(){
    bool f = false;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; ++j){
            mat[i][j] /= 2;
            if(mat[i][j]&1) f = 1;
        }
    }
    return f;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin>>n>>m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; ++j){
            cin>>mat[i][j];
        }
    }
    ll p = n*m;
    ll k = 1;
    do {
        ll sum = 0;
        vt<int> D(2*mxN,0);
        vt<int> cnt(2*mxN,0);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; ++j){
                D[i+j] += (mat[i][j]&1);
                cnt[i+j]++;
            }
        }

        for(ll i = 0; i < mxN; ++i){
            ll t = 0;
            for(int j = 0; j < 2*mxN && cnt[j]; ++j){
                t += D[j];
                ll nc = cnt[j]-D[j];
                t += min(nc,i);
                if(i > nc) t-= (i-nc)&1;
            }
            sum = max(sum,t);
        }
        ans += ((p-sum)*k);
        k *= 2;
    } while(div());

    cout << ans;

    return 0;
}