#include <bits/stdc++.h>
using namespace std;
struct node {
  int n, m;
  char c[30][30];
  int operator==(const node &o) const {
    int flag;
    if (n == o.n && m == o.m) {
      flag = 1;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
          if (c[i][j] != o.c[i][j]) {
            flag = 0;
            break;
          }
        if (!flag) break;
      }
      if (flag) return 1;
    }
    if (n == o.m && m == o.n) {
      flag = 1;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
          if (c[i][j] != o.c[j][n - i + 1]) {
            flag = 0;
            break;
          }
        if (!flag) break;
      }
      if (flag) return 1;
    }
    if (n == o.n && m == o.m) {
      flag = 1;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
          if (c[i][j] != o.c[n - i + 1][m - j + 1]) {
            flag = 0;
            break;
          }
        if (!flag) break;
      }
      if (flag) return 1;
    }
    if (n == o.m && m == o.n) {
      flag = 1;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
          if (c[i][j] != o.c[m - j + 1][i]) {
            flag = 0;
            break;
          }
        if (!flag) break;
      }
      if (flag) return 1;
    }
    return 0;
  }
};
vector<node> cur;
char ch[30][30];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ch[i][j];
  int ans = 1, ax = n, ay = m;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      if (n % x) continue;
      if (m % y) continue;
      if (x == n && y == m) continue;
      cur.clear();
      for (int i = 1; i <= n / x; i++)
        for (int j = 1; j <= m / y; j++) {
          node v;
          v.n = x;
          v.m = y;
          for (int a = (i - 1) * x + 1; a <= i * x; a++)
            for (int b = (j - 1) * y + 1; b <= j * y; b++)
              v.c[a - (i - 1) * x][b - (j - 1) * y] = ch[a][b];
          cur.push_back(v);
        }
      int flag = 1;
      for (int a = 0; a < cur.size(); a++)
        for (int b = a + 1; b < cur.size(); b++)
          if (cur[a] == cur[b]) flag = 0;
      if (flag) {
        ans++;
        if (x * y < ax * ay || x * y == ax * ay && x < ax) ax = x, ay = y;
      }
    }
  cout << ans << endl;
  cout << ax << " " << ay << endl;
  return 0;
}
