#include <bits/stdc++.h>
using namespace std;
long long md = 2000000063;
long long bs = 257;
int I, J;
char maze[22][22];
vector<string> v[2], mn;
set<vector<string> > vis;
bool ok(int ii, int jj) {
  v[0] = vector<string>(ii, string(jj, ' '));
  vis.clear();
  for (int i = 0; i < I; i += ii)
    for (int j = 0; j < J; j += jj) {
      for (int a = 0; a < ii; a++)
        for (int b = 0; b < jj; b++) v[0][a][b] = maze[i + a][j + b];
      mn = v[0];
      int from = 0, to = 1;
      for (int k = 0; k < 3; k++, swap(from, to), swap(ii, jj)) {
        v[to] = vector<string>(jj, string(ii, ' '));
        for (int a = 0; a < ii; a++)
          for (int b = 0; b < jj; b++) v[to][jj - b - 1][a] = v[from][a][b];
        mn = min(mn, v[to]);
      }
      swap(ii, jj);
      if (!vis.insert(mn).second) return 0;
    }
  return 1;
}
int main() {
  scanf("%d%d", &I, &J);
  for (int i = 0; i < I; i++) scanf("%s", maze[i]);
  int cnt = 0, ri = 22, rj = 22;
  for (int i = 1; i <= I; i++)
    if (I % i == 0)
      for (int j = 1; j <= J; j++)
        if (J % j == 0)
          if (ok(i, j)) {
            cnt++;
            if (i * j < ri * rj || (i * j == ri * rj && i < ri)) {
              ri = i;
              rj = j;
            }
          }
  printf("%d\n%d %d\n", cnt, ri, rj);
  return 0;
}
