#include <bits/stdc++.h>
using namespace std;
int n, m, mn = 625, ki = 25, kj = 25, cnt;
vector<string> v;
string s[25];
void check(int ax, int ay, int bx, int by) {
  string t = "", ans;
  for (int i = ax; i < bx; i++)
    for (int j = ay; j < by; j++) t += s[i][j];
  ans = t;
  t = "";
  for (int i = bx - 1; i >= ax; i--)
    for (int j = by - 1; j >= ay; j--) t += s[i][j];
  ans = min(ans, t);
  if (bx - ax == by - ay) {
    t = "";
    for (int j = by - 1; j >= ay; j--)
      for (int i = ax; i < bx; i++) t += s[i][j];
    ans = min(ans, t);
    t = "";
    for (int j = ay; j < by; j++)
      for (int i = bx - 1; i >= ax; i--) t += s[i][j];
    ans = min(ans, t);
  }
  v.push_back(ans);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    if (n % i != 0) continue;
    for (int j = 1; j <= m; j++) {
      if (m % j != 0) continue;
      v.clear();
      for (int ii = 0; ii < n / i; ii++)
        for (int jj = 0; jj < m / j; jj++)
          check(ii * i, jj * j, ii * i + i, jj * j + j);
      bool sign = false;
      sort(v.begin(), v.end());
      for (int k = 0; k < v.size() - 1; k++)
        if (v[k] == v[k + 1]) sign = true;
      if (sign) continue;
      if (mn > i * j) {
        mn = i * j;
        ki = i;
        kj = j;
      }
      cnt++;
    }
  }
  cout << cnt << endl << ki << " " << kj << endl;
  return 0;
}
