#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, l, u, r, b, ans = INT_MAX;
int pic[2600][2600], sum[2600][2600];
int main() {
  scanf("%d %d", &n, &m);
  char s[m + 1];
  for (auto i = (1); i < (n + 1); i++) {
    scanf("%s", s);
    for (auto j = (1); j < (m + 1); j++) {
      pic[i][j] = s[j - 1] - '0';
      if (i == 0)
        sum[i][j] = pic[i][j] + (j > 0 ? sum[i][j - 1] : 0);
      else if (j == 0)
        sum[i][j] = pic[i][j] + (i > 0 ? sum[i - 1][j] : 0);
      else
        sum[i][j] =
            pic[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (auto k = (2); k < (2501); k++) {
    l = 1, i = 0;
    while (l <= m) {
      r = min(m, l + k - 1), u = 1;
      while (u <= n) {
        b = min(n, u + k - 1);
        if (l == 1 && u == 1)
          j = sum[b][r];
        else if (l == 1)
          j = sum[b][r] - sum[u - 1][r];
        else if (u == 1)
          j = sum[b][r] - sum[b][l - 1];
        else
          j = sum[b][r] - sum[b][l - 1] - sum[u - 1][r] + sum[u - 1][l - 1];
        i += min(j, k * k - j);
        u += k;
      }
      l += k;
    }
    ans = min(ans, i);
  }
  printf("%d", ans);
  return 0;
}
