#include <bits/stdc++.h>
using namespace std;
int m, n;
string s[2505];
int a[2505][2505], accum[2505][2505];
int get_sum(int xa, int ya, int xb, int yb) {
  return accum[xb][yb] - accum[xa - 1][yb] - accum[xb][ya - 1] +
         accum[xa - 1][ya - 1];
}
int main() {
  scanf("%d %d", &m, &n);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      a[i + 1][j + 1] = s[i][j] - '0';
      accum[i + 1][j + 1] = a[i + 1][j + 1];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 2; j <= n; j++) {
      accum[i][j] += accum[i][j - 1];
    }
  }
  for (int j = 1; j <= n; j++) {
    for (int i = 2; i <= m; i++) {
      accum[i][j] += accum[i - 1][j];
    }
  }
  int ret = m * n;
  for (int k = 2; k <= m && k <= n; k++) {
    int candidate = 0;
    for (int i = 1; i <= m; i += k) {
      for (int j = 1; j <= n; j += k) {
        int i2 = min(i + k - 1, m);
        int j2 = min(j + k - 1, n);
        int area = k * k;
        int value = get_sum(i, j, i2, j2);
        if (value <= area / 2) {
          candidate += value;
        } else {
          candidate += area - value;
        }
      }
    }
    if (ret > candidate) {
      ret = candidate;
    }
  }
  printf("%d\n", ret);
  return 0;
}
