#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int s[2510][2510];
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    memset(s, 0, sizeof(s));
    char ch;
    getchar();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%c", &ch);
        s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (int)(ch - '0');
      }
      getchar();
    }
    int ans = inf;
    for (int k = 2; k <= 2500; k++) {
      int temp = 0;
      for (int i = k; i <= n + k; i += k) {
        for (int j = k; j <= m + k; j += k) {
          int x1 = min(i, n);
          int y1 = min(j, m);
          int x2 = i - k;
          int y2 = j - k;
          int t = s[x1][y1] - s[x1][y2] - s[x2][y1] + s[x2][y2];
          temp += min(k * k - t, t);
        }
      }
      ans = min(temp, ans);
    }
    printf("%d\n", ans);
  }
  return 0;
}
