#include <bits/stdc++.h>
using namespace std;
const long long N = 30;
char C[N][N];
long long n, m;
unordered_set<string> s;
long long rotate(long long x, long long y, long long h, long long w) {
  string str[5];
  for (long long i = 1; i <= h; i++) {
    for (long long j = 1; j <= w; j++) str[1] += C[i + x - 1][j + y - 1];
    str[1] += '\n';
  }
  for (long long i = h; i >= 1; i--) {
    for (long long j = w; j >= 1; j--) str[2] += C[i + x - 1][j + y - 1];
    str[2] += '\n';
  }
  for (long long j = 1; j <= w; j++) {
    for (long long i = h; i >= 1; i--) str[3] += C[i + x - 1][j + y - 1];
    str[3] += '\n';
  }
  for (long long j = w; j >= 1; j--) {
    for (long long i = 1; i <= h; i++) str[4] += C[i + x - 1][j + y - 1];
    str[4] += '\n';
  }
  for (long long i = 1; i <= 4; i++)
    if (s.find(str[i]) != s.end()) return 1;
  s.insert(str[1]);
  return 0;
}
long long legal(long long h, long long w) {
  if (n % h || m % w) return 0;
  s.clear();
  for (long long i = 1; i <= n; i += h)
    for (long long j = 1; j <= m; j += w)
      if (rotate(i, j, h, w)) return 0;
  return 1;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> C[i][j];
  vector<pair<long long, long long> > ans;
  for (long long h = 1; h <= n; h++)
    for (long long w = 1; w <= m; w++)
      if (legal(h, w)) ans.push_back({h, w});
  pair<long long, long long> anspair = {1000, 1000};
  for (auto pr : ans)
    if (pr.first * pr.second < anspair.first * anspair.second) anspair = pr;
  cout << ans.size() << '\n' << anspair.first << ' ' << anspair.second << '\n';
}
