#include <bits/stdc++.h>
#define MAXN 1501

using namespace std;

typedef long long ll;

ll mat[MAXN][MAXN];
bool mb[MAXN][MAXN];
ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> mat[i][j];
        }
    }
    if(n == 1) ///Druga grupa (10) - n = 1
    {
        ll rez = 0;
        for(int c = 1; c <= 31; c++)
        {
            for(int i = 1; i <= n; i++)
            {
                for(int j = 1; j <= m; j++)
                {
                    mb[i][j] = ((mat[i][j] - ((mat[i][j] >> c) << c)) >> (c - 1));
                }
            }
            ll sum = 0;
            for(int j = 1; j <= m; j++)
            {
                sum += mb[1][j];
            }
            sum = min(sum, m - sum);
            rez += (sum << (c - 1));
        }
        cout << rez;
    }
    else if(n == 2) ///Treca grupa (20) - n = 2
    {
        ll rez = 0;
        for(int c = 1; c <= 31; c++)
        {
            for(int i = 1; i <= n; i++)
            {
                for(int j = 1; j <= m; j++)
                {
                    mb[i][j] = ((mat[i][j] - ((mat[i][j] >> c) << c)) >> (c - 1));
                }
            }
            for(int i = 1; i <= m; i++) a[i] = 0;
            ll parnepar = 0;
            for(int i = m; i >= 2; i--)
            {
                if((mb[1][i] + parnepar) % 2 == 1)
                {
                    a[i] = 1;
                    parnepar++;
                }
            }
            for(int i = 1; i <= m; i++) a[i] += a[i - 1];
            ll sum = 0;
            for(int i = m; i >= 2; i--)
            {
                sum += (mb[2][i] + a[i]) % 2;
            }
            sum += mb[2][1];
            sum += (mb[1][1] + a[m]) % 2;
            sum = min(sum, m + 1 - sum);
            rez += (sum << (c - 1));
        }
        cout << rez;
    }
    return 0;
}