#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 1510

using namespace std;

int n, m;
ll a[MAXN][MAXN];
ll ress, dva[40];

int main()
{
    cin>>n>>m;

    dva[0]=1;
    for (int i=1; i<35; i++) dva[i]=(dva[i-1]*2LL);
    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin>>a[i][j];
    if (n==1)
    {
        for (ll i=0; i<35; i++)
        {
            int k=0;
            for (int j=1; j<=m; j++)
            {
                if (a[1][j]&(dva[i])) k++;
            }
            ll minn=min(k, m-k);
            //cout<<i<<" "<<minn<<endl;
            ress+=(dva[i])*minn;
        }
        cout<<ress;
    }
}