#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m, d = (1 << 30), p[3005][3005];
int f(int sr, int sc, int k) {
  int er = min(sr + k - 1, n), ec = min(sc + k - 1, m);
  return p[er][ec] - p[sr - 1][ec] - p[er][sc - 1] + p[sr - 1][sc - 1];
}
int g(int k) {
  int s = 0;
  for (int i = 1; i <= n; i += k) {
    for (int j = 1; j <= m; j += k) {
      s += min(f(i, j, k), k * k - f(i, j, k));
    }
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  cerr.precision(7);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      p[i][j] = c - '0';
      p[i][j] += p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
    }
  }
  for (int v = 2; v <= max(n, m) + 1; v++) d = min(d, g(v));
  cout << d;
  return 0;
}
