#include <bits/stdc++.h>
using namespace std;
int A, B;
char ar[100][100];
vector<string> rot(vector<string> o) {
  int x = o.size(), y = o[0].size();
  vector<string> r(y);
  for (int i = 0; i < (int)y; i++)
    for (int j = 0; j < (int)x; j++) r[i] += " ";
  for (int i = 0; i < (int)x; i++)
    for (int j = 0; j < (int)y; j++) r[j][x - i - 1] = o[i][j];
  return r;
}
bool good(int x, int y) {
  vector<vector<string> > p;
  for (int i = 0; i < A; i += x)
    for (int j = 0; j < B; j += y) {
      vector<string> c(x);
      for (int k = 0; k < x; k++)
        for (int l = 0; l < y; l++) c[k] += ar[i + k][j + l];
      for (int o = 0; o < (int)p.size(); o++) {
        for (int e = 0; e < (int)4; e++) {
          if (p[o] == c) return false;
          c = rot(c);
        }
      }
      p.push_back(c);
    }
  return true;
}
int main() {
  scanf("%d%d", &A, &B);
  for (int i = 0; i < (int)A; i++) scanf("%s", ar[i]);
  int res = 0;
  int ax = 9999, ay = 9999;
  for (int X = 1; X <= A; X++)
    for (int Y = 1; Y <= B; Y++)
      if (A % X == 0 && B % Y == 0 && good(X, Y)) {
        res++;
        if (make_pair(X * Y, X) < make_pair(ax * ay, ax)) ax = X, ay = Y;
      }
  printf("%d\n%d %d\n", res, ax, ay);
}
