#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, m; cin >> n >> m;
	vector<vector<int>> mat(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)	
			cin >> mat[i][j];
		
	
	if (n == 1)
	{
		ll sol = 0;

		ll mask = 1;
		for (int t = 0; t <= 30; t++, mask <<= 1)
		{
			int cnt = 0;
			for (int i = 0; i < m; i++)
				if (mat[0][i] & mask)
					cnt++;
			
			int min_cnt = min(m - cnt, cnt);
			sol += mask * min_cnt;
		}
		cout << sol;
	}

	return 0;
}