#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int x, y, a, b;
  int ans, ansn, ansm;
  string s, t, p;
  bool flag;
  char puz[30][30];
  ans = ansn = ansm = 0;
  map<string, bool> exs;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", &puz[i][1]);
  for (int i = 1; i <= n; ++i) {
    if (n % i != 0) continue;
    for (int j = 1; j <= m; ++j) {
      if (m % j != 0) continue;
      flag = true;
      exs.clear();
      for (x = 1; x <= n && flag; x += i) {
        for (y = 1; y <= m; y += j) {
          s.clear();
          t.clear();
          for (int a = x; a < x + i; ++a) {
            for (int b = y; b < y + j; ++b) {
              s += puz[a][b];
            }
          }
          for (int b = y; b < y + j; ++b) {
            for (int a = x + i - 1; a >= x; --a) {
              t += puz[a][b];
            }
          }
          if (exs[s] == false)
            exs[s] = true;
          else {
            flag = false;
            break;
          }
          p = s;
          std::reverse(s.begin(), s.end());
          if (p != s) {
            if (exs[s] == false)
              exs[s] = true;
            else {
              flag = false;
              break;
            }
          }
          if (s != t && p != t && i == j) {
            if (exs[t] == false)
              exs[t] = true;
            else {
              flag = false;
              break;
            }
            p = t;
            std::reverse(t.begin(), t.end());
            if (p != t) {
              if (exs[t] == false)
                exs[t] = true;
              else {
                flag = false;
                break;
              }
            }
          }
        }
      }
      if (flag) {
        ++ans;
        if (ans == 1) {
          ansn = i;
          ansm = j;
        } else {
          if (i * j < ansn * ansm) {
            ansn = i;
            ansm = j;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  printf("%d %d\n", ansn, ansm);
}
