#include <bits/stdc++.h>
long f[2500 + 5][2500 + 5], sum[2500 + 5][2500 + 5], ans[2500 + 5][2500 + 5],
    total[2500 + 5][2500 + 5];
long min(long a, long b) {
  if (a > b)
    return b;
  else
    return a;
}
long max(long a, long b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  long n, m, total, t;
  long i, j, len, g, x, y;
  char c;
  scanf("%ld%ld", &n, &m);
  for (i = 1; i <= n; i++) {
    sum[i][0] = 0;
    scanf("%c", &c);
    for (j = 1; j <= m; j++) {
      scanf("%c", &c);
      if (c == '1')
        f[i][j] = 1;
      else
        f[i][j] = 0;
      sum[i][j] = sum[i][j - 1] + f[i][j];
    }
  }
  ans[0][0] = 0;
  for (j = 1; j <= m; j++) {
    ans[0][j] = 0;
    for (i = 1; i <= n; i++) ans[i][j] = ans[i - 1][j] + sum[i][j];
  }
  total = n * m;
  for (len = 2; len <= max(n, m); len++) {
    t = 0;
    for (i = len; i < n + len; i += len)
      for (j = len; j < m + len; j += len) {
        x = min(i, n);
        y = min(j, m);
        g = ans[x][y] - ans[i - len][y] - ans[x][j - len] +
            ans[i - len][j - len];
        if (i <= n && j <= m)
          t += min(g, (x - i + len) * (y - j + len) - g);
        else
          t += min(g, len * len - g);
      }
    total = min(total, t);
  }
  printf("%ld\n", total);
  return 0;
}
