#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 1510;

long long a[MAX][MAX];

vector<int> neg;

int main()
{
    int n, m;

    scanf("%d%d", &n, &m);

    for(long long i = 0; i < n; i++)
        for(long long j = 0; j < m; j++)
            scanf("%lld", &a[i][j]);

    long long blacks = 0;
    long long diagBlacks = 0;
    long long p = 1;
    long long sol = 0;

    for(int i = 0; i < 30; i++)
    {
        blacks = 0;
        for(int j = 0; j < m+n-1; j++)
        {
            diagBlacks = 0;
            for(int k = min(j, m-1); k >= max(j-n+1, 0); k--)
            {
                if((a[j-k][k]>>i)%2)//menjaj
                {
                    diagBlacks++;
                    //printf("%d %d\n");
                }

            }
            diagBlacks = diagBlacks%2;
            blacks+= diagBlacks;
        }
        blacks = min(blacks, n+m-1-blacks);

        sol += blacks*p;
        p = p*2;
    }

    printf("%lld\n", sol);

    return 0;
}