#include <bits/stdc++.h>
using namespace std;
string board[30];
vector<string> v;
string func(int x1, int y1, int x2, int y2) {
  int x = x2 - x1, y = y2 - y1;
  string ans, t;
  t = "";
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) t += board[x1 + i][y1 + j];
  }
  ans = t;
  t = "";
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) t += board[x2 - 1 - i][y2 - 1 - j];
  }
  ans = min(ans, t);
  if (x == y) {
    t = "";
    for (int i = 0; i < y; i++)
      for (int j = 0; j < x; j++) t += board[x1 + j][y2 - 1 - i];
    ans = min(ans, t);
    t = "";
    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) t += board[x2 - 1 - j][y1 + i];
    }
    ans = min(ans, t);
  }
  return ans;
}
int main() {
  int X, Y, ans = 0, ansx = -1, ansy = -1;
  cin >> X >> Y;
  for (int i = 0; i < X; i++) cin >> board[i];
  for (int x = 1; x <= X; x++) {
    if (X % x == 0) {
      for (int y = 1; y <= Y; y++) {
        if (Y % y == 0) {
          v.clear();
          for (int i = 0; i < X / x; i++)
            for (int j = 0; j < Y / y; j++)
              v.push_back(func(i * x, j * y, i * x + x, j * y + y));
          sort(v.begin(), v.end());
          bool good = 1;
          for (int i = 0; i < v.size() - 1; i++)
            if (v[i] == v[i + 1]) good = 0;
          if (good == 1) {
            ans++;
            if (ansx == -1 || x * y < ansx * ansy) {
              ansx = x;
              ansy = y;
            }
          }
        }
      }
    }
  }
  cout << ans << "\n" << ansx << " " << ansy << "\n";
  return 0;
}
