#include <bits/stdc++.h>
using namespace std;
pair<string, int> c[10010];
string s[50];
int n, m;
int k = 0, x, y;
void conv(int xa, int ya, int xb, int yb) {
  string r = "", d = "";
  for (int i = xa; i < xb; i++)
    for (int j = ya; j < yb; j++) r += s[i][j];
  for (int i = xb - 1; i >= xa; i--)
    for (int j = yb - 1; j >= ya; j--) d += s[i][j];
  if (d < r) r = d;
  if (xb - xa != yb - ya) {
    c[k++] = make_pair(r, x);
    for (int i = 0; i < x * y; i++) r[i] = 'a';
  }
  d = "";
  for (int j = ya; j < yb; j++)
    for (int i = xb - 1; i >= xa; i--) d += s[i][j];
  if (d < r) r = d;
  d = "";
  for (int j = yb - 1; j >= ya; j--)
    for (int i = xa; i < xb; i++) d += s[i][j];
  if (d < r) r = d;
  c[k++] = make_pair(r, y);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> s[i];
  int r = 0, rx, ry;
  for (x = 1; x <= n; x++)
    if (n % x == 0)
      for (y = 1; y <= m; y++)
        if (m % y == 0) {
          k = 0;
          for (int a = 0; a * x < n; a++)
            for (int b = 0; b * y < m; b++) {
              conv(a * x, b * y, (a + 1) * x, (b + 1) * y);
            }
          sort(c, c + k);
          bool q = true;
          for (int i = 1; i < k; i++)
            if (c[i] == c[i - 1]) {
              q = false;
              break;
            }
          if (q)
            if (++r == 1 || x * y < rx * ry) {
              rx = x;
              ry = y;
            }
        }
  printf("%d\n", r);
  printf("%d %d\n", rx, ry);
  return 0;
}
