#include <iostream>
#include <algorithm>
using namespace std;
int b[1500][1500];
int zbir(int n, int m){
	int a = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a += b[i][j];
			}
		}
	return a;
}
int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int a[n][m];
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			b[i][j] = a[i][j];
		}
	}
	int t = zbir(n, m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < n; k++) {
				for (int l = 0; l < m; l++) b[k][l] = a[k][l] ^ a[i][j];
			}
			t = min(t, zbir(n, m));
		}
	}
	cout << t;
	return 0;
}