#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[25];
set<string> st;
bool good(int x, int y) {
  st.clear();
  for (int i = 0; i < n; i += x) {
    for (int j = 0; j < m; j += y) {
      string t = "nanatoday";
      string ss = "";
      for (int ii = i; ii < i + x; ii++) {
        for (int jj = j; jj < j + y; jj++) {
          ss += s[ii][jj];
        }
      }
      t = min(t, ss);
      ss = "";
      for (int ii = i + x - 1; ii >= i; ii--) {
        for (int jj = j + y - 1; jj >= j; jj--) {
          ss += s[ii][jj];
        }
      }
      t = min(t, ss);
      if (x == y) {
        ss = "";
        for (int jj = j; jj < j + y; jj++) {
          for (int ii = i + x - 1; ii >= i; ii--) {
            ss += s[ii][jj];
          }
        }
        t = min(t, ss);
        ss = "";
        for (int jj = j + y - 1; jj >= j; jj--) {
          for (int ii = i; ii < i + x; ii++) {
            ss += s[ii][jj];
          }
        }
        t = min(t, ss);
      }
      if (st.count(t)) {
        return 0;
      }
      st.insert(t);
    }
  }
  return 1;
}
int rx = 100, ry = 100, res;
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) continue;
    for (int j = 1; j <= m; j++) {
      if (m % j) continue;
      if (!good(i, j)) continue;
      if (i * j < rx * ry || (i * j == rx * ry && i < rx)) rx = i, ry = j;
      res++;
    }
  }
  cout << res << "\n" << rx << " " << ry;
  return 0;
}
