#include <bits/stdc++.h>
char s[100];
char a[30][30], b[30][30], c[30][30], bb[30][30];
int i, j, n, m, kn, km, x, y, a1, b1, a2, b2, xx, yy, sw, x2, y2;
int ansx, ansy, kol, pt;
int comp() {
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      if (b[i][j] != c[i][j]) return 0;
    }
  }
  return 1;
}
int check() {
  xx = (a1 - 1) * x;
  yy = (b1 - 1) * y;
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      b[i][j] = a[xx + i][yy + j];
    }
  }
  xx = (a2 - 1) * x;
  yy = (b2 - 1) * y;
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      c[i][j] = a[xx + i][yy + j];
    }
  }
  if (comp() == 1) return 1;
  x2 = x;
  y2 = y;
  for (int ii = 1; ii <= 3; ii++) {
    for (int i = 1; i <= x2; i++) {
      for (int j = 1; j <= y2; j++) {
        bb[j][x2 - i + 1] = b[i][j];
      }
    }
    sw = x2;
    x2 = y2;
    y2 = sw;
    for (int i = 1; i <= x2; i++) {
      for (int j = 1; j <= y2; j++) {
        b[i][j] = bb[i][j];
      }
    }
    if (ii == 2) {
      if (comp() == 1) return 1;
    } else if (x == y) {
      if (comp() == 1) return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", &s);
    for (j = 1; j <= m; j++) {
      a[i][j] = s[j - 1];
    }
  }
  ansx = 0;
  ansy = 0;
  kol = 0;
  for (x = 1; x <= n; x++) {
    if (n % x != 0) continue;
    kn = n / x;
    for (y = 1; y <= m; y++) {
      if (m % y != 0) continue;
      km = m / y;
      pt = 0;
      for (a1 = 1; a1 <= kn; a1++) {
        for (b1 = 1; b1 <= km; b1++) {
          for (a2 = a1; a2 <= kn; a2++) {
            if (a2 == a1)
              b2 = b1 + 1;
            else
              b2 = 1;
            for (; b2 <= km; b2++) {
              if (check() == 1) pt = 1;
            }
          }
        }
      }
      if (pt == 0) {
        kol++;
        if (ansx == 0) {
          ansx = x;
          ansy = y;
        } else if ((ansx * ansy > x * y) ||
                   ((ansx * ansy == x * y) && (ansx > x))) {
          ansx = x;
          ansy = y;
        }
      }
    }
  }
  printf("%d\n", kol);
  printf("%d %d", ansx, ansy);
  return 0;
}
