#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, m, a, dp[2509][2509];
int main() {
  scanf("%d%d", &n, &m);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%1d", &a);
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (a) dp[i][j]++;
    }
  }
  int ma = max(n, m), ans = 1e9;
  for (int k = 2; k <= ma; k++) {
    int buf = 0, area = k * k;
    for (int i = 0; i < n; i += k) {
      for (int j = 0; j < m; j += k) {
        int res, aa = i + k, bb = j + k;
        if (aa > n) aa = n;
        if (bb > m) bb = m;
        res = dp[aa][bb] - dp[aa][j] - dp[i][bb] + dp[i][j];
        if (area - res < res) res = area - res;
        buf += res;
        if (buf >= ans) break;
      }
      if (buf >= ans) break;
    }
    if (buf < ans) ans = buf;
  }
  printf("%d\n", ans);
  return 0;
}
