#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0, as = 1e9, a1, a2;
map<string, pair<int, int> > e;
char a[33][33];
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) gets(a[i]);
  for (int ii = 1; ii <= n; ii++)
    for (int jj = 1; jj <= m; jj++)
      if (n % ii == 0 && m % jj == 0) {
        e.clear();
        int t = 0;
        for (int i = 0; i < n / ii; i++)
          for (int j = 0; j < m / jj; j++) {
            string s = "";
            for (int x = 0; x < ii; x++)
              for (int y = 0; y < jj; y++) s += a[i * ii + x][j * jj + y];
            if (e.find(s) != e.end() && e[s] != make_pair(i + 1, j)) t = 1;
            e[s] = make_pair(i + 1, j);
            s = "";
            for (int x = 0; x < ii; x++)
              for (int y = 0; y < jj; y++)
                s += a[i * ii + ii - x - 1][j * jj + jj - y - 1];
            if (e.find(s) != e.end() && e[s] != make_pair(i + 1, j)) t = 1;
            e[s] = make_pair(i + 1, j);
            if (ii == jj) {
              s = "";
              for (int x = 0; x < ii; x++)
                for (int y = 0; y < jj; y++)
                  s += a[i * ii + ii - y - 1][j * jj + x];
              if (e.find(s) != e.end() && e[s] != make_pair(i + 1, j)) t = 1;
              e[s] = make_pair(i + 1, j);
              s = "";
              for (int x = 0; x < ii; x++)
                for (int y = 0; y < jj; y++)
                  s += a[i * ii + y][j * jj + ii - x - 1];
              if (e.find(s) != e.end() && e[s] != make_pair(i + 1, j)) t = 1;
              e[s] = make_pair(i + 1, j);
            }
          }
        if (!t) {
          ans++;
          if (ii * jj < as || ii * jj == as && ii < a1)
            as = ii * jj, a1 = ii, a2 = jj;
        }
      }
  cout << ans << endl << a1 << " " << a2 << endl;
  return 0;
}
