#include <bits/stdc++.h>
using namespace std;
string inp[25];
map<pair<string, pair<int, int> >, int> ok;
char data[25][25];
string rotate1(string now, int row) {
  int len = now.size();
  int col = len / row;
  int pos = 0;
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
      data[i][j] = now[pos++];
    }
  }
  string tmp = "";
  for (int j = col - 1; j >= 0; j--) {
    for (int i = 0; i < row; i++) {
      tmp += data[i][j];
    }
  }
  return tmp;
}
bool Find(string now, int row) {
  int col = now.size() / row;
  pair<string, pair<int, int> > tmp;
  tmp = make_pair(now, make_pair(row, col));
  if (ok.find(tmp) != ok.end()) {
    return 1;
  }
  string yes = rotate1(now, row);
  swap(row, col);
  tmp = make_pair(yes, make_pair(row, col));
  if (ok.find(tmp) != ok.end()) {
    return 1;
  }
  yes = rotate1(yes, row);
  swap(row, col);
  tmp = make_pair(yes, make_pair(row, col));
  if (ok.find(tmp) != ok.end()) {
    return 1;
  }
  yes = rotate1(yes, row);
  swap(row, col);
  tmp = make_pair(yes, make_pair(row, col));
  if (ok.find(tmp) != ok.end()) return 1;
  return 0;
}
int main() {
  int n, m;
  int t = 0;
  map<int, string> ok2;
  pair<string, pair<int, int> > tmp2;
  scanf("%d %d", &n, &m);
  int cnt = 0;
  for (int i = 0; i < n; i++) cin >> inp[i];
  int area = 10000000;
  int x = 25;
  int y;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (n % i == 0 && m % j == 0) {
        ok.clear();
        int yes = 1;
        for (int l = 0; l < n; l += i) {
          for (int p = 0; p < m; p += j) {
            string tmp = "";
            for (int q = l; q < l + i; q++) {
              for (int r = p; r < p + j; r++) {
                tmp += inp[q][r];
              }
            }
            int pre = Find(tmp, i);
            if (pre) {
              yes = 0;
              break;
            } else {
              tmp2 = make_pair(tmp, make_pair(i, j));
              ok[tmp2] = ++t;
            }
          }
        }
        if (yes == 1) {
          cnt++;
          int tot = i * j;
          if (tot < area) {
            area = tot;
            x = i;
            y = j;
          } else if (area == tot) {
            if (x > i) x = i;
          }
        }
      }
    }
  }
  cout << cnt << endl;
  cout << x << " " << y << endl;
  return 0;
}
