#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    unsigned l=n+m-1;
    unsigned a[l]{},h,c[32]{},f=0,s=0;
    for(int y=0;y<n;y++)
        for(int x=0;x<m;x++){
            cin>>h;
            a[x+y]^=h;
        }
    for(int i=0;i<32;i++){
        for(unsigned r:a)
            c[i]+=r&(1<<i);
        c[i]=2*c[i]>l;
    }
    for(int i=31;i>=0;i--)
        f=c[i]+(f<<1);
    for(int i=0;i<l;i++)
        s+=a[i]^f;
    cout<<s;
    return 0;}