# include <bits/stdc++.h>
using namespace std;
# define For(i, s, t) for (int i = (s), _ = (t); i < _; i ++)
# define LL long long
const int S = 1 << 20 | 5;
int n, m, a[10][10000];
int fu, sum[S], nx[S];
struct comp {
	LL x, y;
	comp(LL _x = 0, LL _y = 0) : x(_x), y(_y) {}
	friend comp operator + (comp A, comp B) {
		return comp(A.x + B.x, A.y + B.y);
	}
	friend comp operator - (comp A, comp B) {
		return comp(A.x - B.x, A.y - B.y);
	}
	friend comp operator * (comp A, comp B) {
		return comp(A.x * B.x - A.y * B.y, A.x * B.y + A.y * B.x);
	}
	comp operator / (LL w) {
		return comp(x / w, y / w);
	}	
} ii = comp(0, 1), f[S], c[S], ans[S];
void FWT(comp * A, int sign) {
	for (int i = 4; i <= fu; i <<= 2)
		for (int j = 0; j < fu; j += i)
			For (k, 0, i / 4) {
				comp	& x = A[j + k], & y = A[j + k + i / 4], & z = A[j + k + i / 2], & w = A[j + k + i / 4 * 3], 
						X = x, Y = y, Z = z, W = w;
				sign == +1 ? (
					x = X + Y + Z + W, 
					y = X + ii * Y - Z - ii * W, 
					z = X - Y + Z - W, 
					w = X - ii * Y - Z + ii * W
				) : (
					x = (X + Y + Z + W) / 4, 
					y = (X - ii * Y - Z + ii * W) / 4, 
					z = (X - Y + Z - W) / 4, 
					w = (X + ii * Y - Z - ii * W) / 4
				);
			}
}
int main() {
	# ifndef ONLINE_JUDGE
		freopen("tab.in", "r", stdin);
	# endif
	scanf("%d %d", & n, & m);
	For (i, 0, n)
		For (j, 0, m)
			scanf("%d", & a[i][j]);
	fu = 1 << 2 * n;
	For (s, 0, fu)
		sum[s] = sum[s >> 2] + (s & 3);
	For (s, 0, fu)
		For (i, 0, n)
			nx[s] |= ((s >> 2 * i & 3) + 1 & 3) << 2 * i;
	For (s, 0, fu) {
		int t = nx[nx[s]];
		f[s] = min(min(sum[s], sum[nx[s]]), min(sum[t], sum[nx[t]]));
	}
	For (j, 0, m) {
		int s = 0;
		For (i, 0, n)
			s |= a[i][j] << 2 * i;
		c[s].x ++;
	}
	For (s, 0, fu)
		if (s < fu - 1 - s)
			swap(c[s], c[fu - 1 - s]);
	FWT(c, +1);
	FWT(f, +1);
	For (s, 0, fu)
		ans[s] = c[s] * f[s];
	FWT(ans, -1);
	int res = ~ 0u >> 2;
	For (s, 0, fu)
		res = min(res, (int)ans[s].x);
	printf("%d\n", res);
	return 0;
}
