#include <bits/stdc++.h>
using namespace std;
int n, m;
string p[(1 << 5)];
char tmp[(1 << 5)];
set<string> S1;
set<string> S2;
pair<int, pair<int, int> > Final[(1 << 5) * (1 << 5)];
int cnt;
inline string Generate(int Len) {
  string Res;
  while (Len--) {
    Res += '0';
  }
  return Res;
}
inline string Rotate(int R, int xx, int yy, int aa, int bb) {
  string Res;
  string r[(1 << 5)];
  if (R == 0) {
    for (int i = xx; i < xx + aa; i++) {
      for (int j = yy; j < yy + bb; j++) {
        Res += p[i][j];
      }
    }
    return Res;
  } else if (R == 1) {
    for (int i = 0; i < bb; i++) {
      r[i] = Generate(aa);
    }
    for (int i = 0; i < aa; i++) {
      for (int j = 0; j < bb; j++) {
        r[j][aa - 1 - i] = p[i + xx][j + yy];
      }
    }
    for (int i = 0; i < bb; i++) {
      for (int j = 0; j < aa; j++) {
        Res += r[i][j];
      }
    }
    return Res;
  } else if (R == 2) {
    for (int i = 0; i < aa; i++) {
      r[i] = Generate(bb);
    }
    for (int i = 0; i < aa; i++) {
      for (int j = 0; j < bb; j++) {
        r[aa - 1 - i][bb - 1 - j] = p[i + xx][j + yy];
      }
    }
    for (int i = 0; i < aa; i++) {
      for (int j = 0; j < bb; j++) {
        Res += r[i][j];
      }
    }
    return Res;
  } else if (R == 3) {
    for (int i = 0; i < bb; i++) {
      r[i] = Generate(aa);
    }
    for (int i = 0; i < aa; i++) {
      for (int j = 0; j < bb; j++) {
        r[bb - 1 - j][i] = p[i + xx][j + yy];
      }
    }
    for (int i = 0; i < bb; i++) {
      for (int j = 0; j < aa; j++) {
        Res += r[i][j];
      }
    }
    return Res;
  } else {
    return "-";
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    p[i] = tmp;
  }
  for (int a = 1; a <= n; a++) {
    if (n % a) {
      continue;
    }
    for (int b = 1; b <= m; b++) {
      if (m % b) {
        continue;
      }
      S1.clear();
      S2.clear();
      bool ok = true;
      for (int x = 0; x < n; x += a) {
        for (int y = 0; y < m; y += b) {
          for (int k = 0; k < 4; k++) {
            if (a == b) {
              string sTmp = Rotate(k, x, y, a, b);
              if (k > 0 && Rotate(0, x, y, a, b) == sTmp) {
                continue;
              } else if (k > 1 && Rotate(1, x, y, a, b) == sTmp) {
                continue;
              } else if (k > 2 && Rotate(2, x, y, a, b) == sTmp) {
                continue;
              } else if (S1.find(sTmp) != S1.end()) {
                ok = false;
                break;
              } else {
                S1.insert(sTmp);
              }
            } else if (k & 1) {
              string sTmp = Rotate(k, x, y, a, b);
              if (k == 3 && Rotate(1, x, y, a, b) == sTmp) {
                continue;
              }
              if (S1.find(sTmp) != S1.end()) {
                ok = false;
                break;
              }
              S1.insert(sTmp);
            } else {
              string sTmp = Rotate(k, x, y, a, b);
              if (k == 2 && Rotate(0, x, y, a, b) == sTmp) {
                continue;
              }
              if (S2.find(sTmp) != S2.end()) {
                ok = false;
                break;
              }
              S2.insert(sTmp);
            }
          }
          if (!ok) {
            break;
          }
        }
        if (!ok) {
          break;
        }
      }
      if (ok) {
        Final[cnt++] = make_pair(a * b, make_pair(a, b));
      }
    }
  }
  sort(Final, Final + cnt);
  printf("%d\n%d %d\n", cnt, Final[0].second.first, Final[0].second.second);
  return 0;
}
