#include <bits/stdc++.h>
using namespace std;
char data[20][20];
bool isgood(int a, int b, int x, int y) {
  set<string> st;
  set<string> tmp;
  string s;
  for (int i = 0; i < a; i += x) {
    for (int j = 0; j < b; j += y) {
      tmp.clear();
      s = "";
      for (int l = 0; l < x; l++) {
        for (int k = 0; k < y; k++) {
          s += data[i + l][j + k];
        }
      }
      if (st.count(s) != 0) {
        return false;
      }
      tmp.insert(s);
      st.insert(s);
      reverse(s.begin(), s.end());
      if (tmp.count(s) == 0) {
        if (st.count(s) != 0) {
          return false;
        }
        tmp.insert(s);
        st.insert(s);
      }
      if (x != y) continue;
      s = "";
      for (int k = y - 1; k >= 0; k--) {
        for (int l = 0; l < x; l++) {
          s += data[i + l][j + k];
        }
      }
      if (tmp.count(s) == 0) {
        if (st.count(s) != 0) {
          return false;
        }
        tmp.insert(s);
        st.insert(s);
      }
      reverse(s.begin(), s.end());
      if (tmp.count(s) == 0) {
        if (st.count(s) != 0) {
          return false;
        }
        tmp.insert(s);
        st.insert(s);
      }
    }
  }
  return true;
}
int main(void) {
  int n, m;
  int minx, miny, cnt = 0;
  int area = 1e9;
  string s;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) {
      data[i][j] = s[j];
    }
  }
  for (int x = 1; x <= n; x++) {
    if (n % x == 0) {
      for (int y = 1; y <= m; y++) {
        if (m % y == 0) {
          if (isgood(n, m, x, y)) {
            cnt++;
            if ((area > x * y) || ((area == x * y) && (x < minx))) {
              minx = x;
              miny = y;
              area = x * y;
            }
          }
        }
      }
    }
  }
  cout << cnt << endl << minx << " " << miny;
  return 0;
}
