#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	
	unsigned long long int n,m;
	cin >>n>>m;
	unsigned long long int bin[32];
	unsigned long long int brojac[32];
	bin[0]=1;
	brojac[0]=0;
	for(int i=1;i<32;i++)
	{
		brojac[i]=0;
		bin[i]=bin[i-1]*2;
	}
	
	for(int i=0;i<m*n;i++)
	{
		unsigned long long int x;
		cin >>x;
		for(int i=0;i<32;i++)
		{
			if(x&bin[i])
			{
				brojac[i]++;
			}
		}
	}
	
	unsigned long long int h=n+m-1;
/*	for(int i=0;i<32;i++)
	{
		cout <<brojac[i]<<" ";
	}
	cout <<"\n";*/
    if(n==1)
    {
	for(int i=0;i<32;i++)
	{
		brojac[i]=brojac[i]%h;
		brojac[i]=min(brojac[i],h-brojac[i]);
	}
    }
	/*for(int i=0;i<32;i++)
	{
		cout <<brojac[i]<<" ";
	}
	cout <<"\n";*/
	unsigned long long int z=0;
	for(int i=0;i<32;i++)
	{
		z+=brojac[i]*bin[i];
		//cout <<z<<" ";
	}
	//cout <<"\n";
	cout <<z<<"\n";
	return 0;
}