#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 1e9;
string s;
int grid[6000][6000];
int slv(int x, int y, int t) {
  int a = x + t - 1, b = y + t - 1;
  return grid[a][b] + grid[x - 1][y - 1] - grid[x - 1][b] - grid[a][y - 1];
}
int calc(int t) {
  int ret = 0;
  for (int i = 1; i <= n; i += t)
    for (int j = 1; j <= m; j += t) {
      int tmp = slv(i, j, t);
      ret += min(t * t - tmp, tmp);
    }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int j = 0; j < n && cin >> s; j++)
    for (int i = 0; i < m; i++) grid[j + 1][i + 1] = s[i] - '0';
  for (int i = 1; i < 6000; i++)
    for (int j = 1; j < 6000; j++)
      grid[i][j] += grid[i - 1][j] + grid[i][j - 1] - grid[i - 1][j - 1];
  for (int i = 2; i < 2500; i++) ans = min(ans, calc(i));
  cout << ans << endl;
  return 0;
}
