#include <bits/stdc++.h>
using namespace std;
int n, m;
int v[2511][2511];
int get(int a, int b) {
  if (a < 0 || b < 0) return 0;
  return v[min(a, n - 1)][min(b, m - 1)];
}
int get(int a, int b, int c, int d) {
  return get(c, d) - get(c, b - 1) - get(a - 1, d) + get(a - 1, b - 1);
}
int get2(int a, int b, int c, int d) {
  return get(c, d) + get(c, b - 1) + get(a - 1, d) - get(a - 1, b - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n >> m) {
    for (int i = 0, __ = n; i < __; i++)
      for (int j = 0, __ = m; j < __; j++) {
        char ch;
        cin >> ch;
        v[i][j] = ch == '1';
      }
    for (int i = 0, __ = n; i < __; i++)
      for (int j = 0, __ = m; j < __; j++) {
        v[i][j] = get2(i, j, i, j);
      }
    int ans = 0x3F3F3F3F;
    for (int k = 2, __ = n + m; k < __; k++) {
      int cur = 0;
      for (int i = 0, __ = n; i < __; i++) {
        if ((i - 1) * k > n) break;
        for (int j = 0, __ = m; j < __; j++) {
          if ((j - 1) * k > m) break;
          int x = get(i * k, j * k, (i + 1) * k - 1, (j + 1) * k - 1);
          cur += min(x, k * k - x);
        }
      }
      ans = min(ans, cur);
    }
    cout << ans << endl;
  }
}
