#include <bits/stdc++.h>
using namespace std;
int n, m, mn = 2e9, cnt, num, s[2505][2505];
bool v[2505];
char a[2505][2505];
int main() {
  int i, j, r, c, tr, tc, sz;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    scanf("%s", &a[i][1]);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j] - '0';
    }
  }
  sz = max(n, m);
  for (i = 2; i <= sz; i++) {
    cnt = 0;
    for (r = 1; r <= n; r += i) {
      for (c = 1; c <= m; c += i) {
        tr = min(r + i - 1, n);
        tc = min(c + i - 1, m);
        num = s[tr][tc] - s[r - 1][tc] - s[tr][c - 1] + s[r - 1][c - 1];
        cnt += min(num, i * i - num);
      }
    }
    mn = min(mn, cnt);
  }
  cout << mn;
  return 0;
}
