#include <bits/stdc++.h>
using namespace std;
const int M = 100 + 10;
char board[M][M];
bool solve(int n, int m, int x, int y) {
  bool ok1 = true;
  for (int row1 = 0; row1 < n / x; row1++) {
    for (int col1 = 0; col1 < m / y; col1++) {
      for (int row2 = 0; row2 < n / x; row2++) {
        for (int col2 = 0; col2 < m / y; col2++) {
          if (row1 != row2 || col1 != col2) {
            int num = 0;
            for (int i = 0; i < x; i++) {
              for (int j = 0; j < y; j++) {
                if (board[row1 * x + i][col1 * y + j] ==
                    board[row2 * x + i][col2 * y + j]) {
                  num++;
                }
              }
            }
            if (num == x * y) {
              ok1 = false;
            }
            num = 0;
            for (int i = 0; i < x; i++) {
              for (int j = 0; j < y; j++) {
                if (board[row1 * x + i][col1 * y + j] ==
                    board[row2 * x + x - 1 - i][col2 * y + y - 1 - j]) {
                  num++;
                }
              }
            }
            if (num == x * y) {
              ok1 = false;
            }
            if (x == y) {
              num = 0;
              for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                  if (board[row1 * x + i][col1 * y + j] ==
                      board[row2 * x + j][col2 * y + y - 1 - i]) {
                    num++;
                  }
                }
              }
              if (num == x * y) {
                ok1 = false;
              }
              num = 0;
              for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                  if (board[row1 * x + i][col1 * y + j] ==
                      board[row2 * x + x - 1 - j][col2 * y + i]) {
                    num++;
                  }
                }
              }
              if (num == x * y) {
                ok1 = false;
              }
            }
          }
        }
      }
    }
  }
  return ok1;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      board[i][j] = s[j];
    }
  }
  int ans = 1E+9;
  int ansx = 1E+9;
  int ansy = 1E+9;
  int good = 0;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      if (n % x == 0 && m % y == 0) {
        bool ok = solve(n, m, x, y);
        if (ok == true) {
          good++;
          if (x * y < ans) {
            ans = x * y;
            ansx = x;
            ansy = y;
          } else {
            if (x * y == ans) {
              if (x < ansx) {
                ansx = x;
                ansy = y;
              }
            }
          }
        }
      }
    }
  }
  cout << good << endl;
  cout << ansx << " " << ansy << endl;
  return 0;
}
