#include <bits/stdc++.h>
using namespace std;
using Long = long long;
using ii = pair<Long, Long>;
const Long INF = INT_MAX;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > grid(5001, vector<int>(5001));
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) grid[i][j] = s[j] == '1';
  }
  int ans = INT_MAX;
  const int maxS = max(n, m);
  vector<vector<int> > acc(5001, vector<int>(5001));
  for (int i = 0; i < 5001; ++i) {
    for (int j = 0; j < 5001; ++j) {
      acc[i][j] = grid[i][j];
      if (j > 0) acc[i][j] += acc[i][j - 1];
    }
  }
  for (int k = 2; k <= maxS; ++k) {
    int currAns = 0;
    for (int i = 0; i < n; i += k) {
      for (int j = 0; j < m; j += k) {
        int ones = 0;
        for (int x = i; x < i + k; ++x) {
          ones += acc[x][j + k - 1];
          if (j > 0) ones -= acc[x][j - 1];
        }
        currAns += min(k * k - ones, ones);
      }
    }
    if (currAns < ans) ans = currAns;
  }
  cout << ans << "\n";
  return 0;
}
