#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans = 1e9;
int s[2510][2510];
int gtsum(int x, int y, int c) {
  int mnx = x - 1, mny = y - 1, mxx = x + c - 1, mxy = y + c - 1;
  if (mxx > n) mxx = n;
  if (mxy > m) mxy = m;
  return s[mxx][mxy] - s[mxx][mny] - s[mnx][mxy] + s[mnx][mny];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char x = ' ';
      while (x != '0' && x != '1') x = getchar();
      if (x == '1') s[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) s[i][j] += s[i][j - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) s[i][j] += s[i - 1][j];
  }
  int mx = max(n, m);
  for (int k = 2; k <= mx; k++) {
    int res = 0;
    int area = k * k;
    bool f = false;
    for (int i = 1; i <= n; i += k) {
      for (int j = 1; j <= m; j += k) {
        int xx = gtsum(i, j, k);
        if (area - xx < xx) xx = area - xx;
        res += xx;
        if (res >= ans) {
          f = true;
          break;
        }
      }
      if (f) break;
    }
    if (!f && res < ans) ans = res;
  }
  printf("%d", ans);
  return 0;
}
