#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> a;
vector<string> rotate(vector<string> a) {
  int n = a.size();
  int m = a[0].size();
  vector<string> res(m, string(n, ' '));
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) res[i][j] = a[j][m - i - 1];
  return res;
}
int good(int x, int y) {
  if (n % x != 0) return 0;
  if (m % y != 0) return 0;
  set<vector<string> > ss;
  for (int ii = 0; ii < n / x; ii++)
    for (int jj = 0; jj < m / y; jj++) {
      vector<string> b(x, string(y, ' '));
      for (int i = 0; i < x; i++)
        for (int j = 0; j < y; j++) b[i][j] = a[ii * x + i][jj * y + j];
      vector<vector<string> > bb;
      for (int i = 0; i < 4; i++) {
        if (ss.count(b)) return 0;
        bb.push_back(b);
        b = rotate(b);
      }
      ss.insert(bb.begin(), bb.end());
    }
  return 1;
}
int main(void) {
  cin >> n >> m;
  a.assign(n, string(m, ' '));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  int an = -1, am = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (good(i + 1, j + 1)) {
        ans++;
        if (an == -1 || (i + 1) * (j + 1) < an * am) {
          an = i + 1;
          am = j + 1;
        }
      }
  cout << ans << endl;
  cout << an << " " << am << endl;
  return 0;
}
