#include <bits/stdc++.h>
using namespace std;
string mat[24];
int n, m;
bool che(int i, int j) {
  map<string, bool> mp;
  for (int ii = 1; ii <= n; ii += i) {
    for (int jj = 1; jj <= m; jj += j) {
      string s2 = "";
      for (int k = ii; k < ii + i; k++) {
        for (int l = jj; l < jj + j; l++) {
          s2 += mat[k - 1][l - 1];
        }
      }
      if (mp[s2]) return false;
      mp[s2] = 1;
      reverse(s2.begin(), s2.end());
      mp[s2] = 1;
      string s3 = "";
      if (i == j) {
        for (int l = jj; l < jj + j; l++) {
          for (int k = ii + i - 1; k >= ii; k--) {
            s3 += mat[k - 1][l - 1];
          }
        }
        mp[s3] = 1;
        reverse(s3.begin(), s3.end());
        mp[s3] = 1;
      }
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  long long ans = 0, mi = INT_MAX, mx = INT_MAX, my = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (n % i == 0 && m % j == 0) {
        if (che(i, j)) {
          ans++;
          if (i * j < mi || (i * j == mi && i < mx)) {
            mi = i * j;
            mx = i;
            my = j;
          }
        }
      }
    }
  }
  cout << ans << "\n";
  cout << mx << " " << my << "\n";
  return 0;
}
