#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> rotate(const vector<vector<char>>& a, int o) {
  int n = a.size(), m = a[0].size();
  vector<vector<char>> b(o % 2 ? m : n, vector<char>(o % 2 ? n : m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (o == 0) b[i][j] = a[i][j];
      if (o == 1) b[j][n - i - 1] = a[i][j];
      if (o == 2) b[n - i - 1][m - j - 1] = a[i][j];
      if (o == 3) b[m - j - 1][i] = a[i][j];
    }
  return b;
}
int main() {
  int n, m;
  char a[20][21];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  set<pair<int, int>> ans;
  for (int dr = 1; dr <= n; dr++)
    if (n % dr == 0)
      for (int dc = 1; dc <= m; dc++)
        if (m % dc == 0) {
          set<vector<vector<char>>> s;
          for (int sr = 0; sr < n; sr += dr)
            for (int sc = 0; sc < m; sc += dc) {
              vector<vector<char>> me(dr, vector<char>(dc));
              for (int r = 0; r < dr; r++)
                for (int c = 0; c < dc; c++) me[r][c] = a[r + sr][c + sc];
              if (s.count(rotate(me, 0))) break;
              if (s.count(rotate(me, 1))) break;
              if (s.count(rotate(me, 2))) break;
              if (s.count(rotate(me, 3))) break;
              s.insert(me);
            }
          if (s.size() == n * m / dr / dc) ans.insert({dr * dc, dr});
        }
  printf("%d\n%d %d\n", ans.size(), ans.begin()->second,
         ans.begin()->first / ans.begin()->second);
}
