#include <bits/stdc++.h>
using namespace std;
char a[2500][2500];
long long d[2501][2501];
int main() {
  long long h, w, an = INT_MAX, c = INT_MAX, o, z, s;
  scanf("%lld%lld", &h, &w);
  for (long long i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) d[i + 1][j + 1] = a[i][j] == '1';
  for (long long i = 1; i <= h; i++)
    for (long long j = 1; j <= 2500; j++) d[i][j] += d[i][j - 1];
  for (long long i = 1; i <= 2500; i++)
    for (long long j = 1; j <= 2500; j++) d[j][i] += d[j - 1][i];
  long long p = max(h, w);
  for (long long k = 2; k <= p; k++) {
    s = 0;
    for (long long i = 1; i <= h; i += k)
      for (long long j = 1; j <= w; j += k) {
        o = 0, z = 0;
        o = d[min(h, i + k - 1)][min(w, j + k - 1)] -
            d[i - 1][min(w, j + k - 1)] - d[min(h, i + k - 1)][j - 1] +
            d[i - 1][j - 1];
        z = k * k - o;
        s += min(o, z);
      }
    an = min(an, s);
  }
  printf("%lld", an);
}
