#include <iostream>

#define MAX_N 1500
#define MAX_M 1500

int A[MAX_N][MAX_M];

int main()
{
	int n, m;
	std::cin >> n >> m;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			std::cin >> A[i][j];

	if (n == 1 || m == 1)
	{
		n = std::max(n, m);
		int* A = (int*)::A;

		int br[30]{ 0 };

		for (int i = 0; i < n; ++i)
		{			
			for (int j = 0; j < 30; ++j)
				br[j] += (A[i] >> j) & 1;
		}

		long long zbir = 0;
		for (int j = 0; j < 30; ++j)
		{
			if (br[j] > n / 2)
				br[j] = n - br[j];

			zbir += ((long long)br[j]) << j;
		}
		
		std::cout << zbir;
	}
	
	return 0;
}