#include <bits/stdc++.h>
using namespace std;
set<string> mp;
char q[40][40];
bool good;
bool contained(int a, int b, int x, int y) {
  string s;
  char w[2];
  w[1] = 0;
  for (int i = a; i < x; i++) {
    for (int j = b; j < y; j++) {
      w[0] = q[i][j];
      s += string(w);
    }
    s += '.';
  }
  if (mp.find(s) != mp.end()) {
    return true;
  }
  return false;
}
void put4(int a, int b, int x, int y) {
  char w[2];
  w[1] = 0;
  {
    string s;
    for (int i = a; i < x; i++) {
      for (int j = b; j < y; j++) {
        w[0] = q[i][j];
        s += string(w);
      }
      s += '.';
    }
    mp.insert(s);
  }
  {
    string s;
    for (int i = x - 1; i >= a; i--) {
      for (int j = y - 1; j >= b; j--) {
        w[0] = q[i][j];
        s += string(w);
      }
      s += '.';
    }
    mp.insert(s);
  }
  {
    string s;
    for (int j = y - 1; j >= b; j--) {
      for (int i = a; i < x; i++) {
        w[0] = q[i][j];
        s += string(w);
      }
      s += '.';
    }
    mp.insert(s);
  }
  {
    string s;
    for (int j = b; j < y; j++) {
      for (int i = x - 1; i >= a; i--) {
        w[0] = q[i][j];
        s += string(w);
      }
      s += '.';
    }
    mp.insert(s);
  }
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++) {
    scanf("%s", q[i]);
  }
  int minSc = 1000000000, minX, minY, ans = 0;
  for (int x = 1; x <= a; x++) {
    for (int y = 1; y <= b; y++) {
      if (a % x == 0 && b % y == 0) {
        good = true;
        mp.clear();
        for (int i = 0; i < a; i += x) {
          for (int j = 0; j < b; j += y) {
            if (contained(i, j, i + x, j + y)) {
              good = false;
            }
            put4(i, j, i + x, j + y);
          }
        }
        if (good) {
          ans++;
          if (x * y < minSc) {
            minSc = x * y;
            minX = x;
            minY = y;
          } else if (x * y == minSc && x < minX) {
            minX = x;
            minY = y;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  printf("%d %d\n", minX, minY);
  return 0;
}
