#include <bits/stdc++.h>

using namespace std;
const int MAXS = 1.5e3;
int a[MAXS][MAXS];
int brBitova[30];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++){
            cin>>a[i][j];
            int x = a[i][j];
            int ind = 0;
            while(x>0){
                brBitova[ind]+=x%2;
                x/=2;
                ind++;
            }
        }
    }
    long long rez = 0,k = 1;
    for(int i = 0; i<30; i++){
        rez+=(long long)min(brBitova[i],n*m-brBitova[i])*k;
        k*=2;
    }
    cout<<rez;
    return 0;
}