#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>

using namespace std;
typedef long long ll;
ll n, m, x = 0, y = 0, ans = 0;

int main()
{
	freopen("video.in", "r", stdin);
	freopen("video.out", "w", stdout);
	cin >> n >> m;
	string s;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		for (int j = 0; j < m; j++)
		{
			if (s[j] == '1')
				x++;
			else
				y++;
		}
	}
	if (x < y)
		swap(x, y);
	ll ans1, ans2;
	ans1 = x;
	ans2 = y;
	ll fl = 0;
	if (ans1 % n == 0 && ans2 % n == 0 && ans1 / n + ans2 / n == m)
		fl++;
	if (ans1 % m == 0 && ans2 % m == 0 && ans1 / m + ans2 / m == n)
		if (fl == 1)
			fl = 0;
		else
			fl = 1;
	ans1 = max(ans1 / 2 - 1, (ll)0);
	ans2 = max(ans2 / 2 - 1, (ll)0);
	cout << ans1 + ans2 + fl;
	return 0;
}