#include <bits/stdc++.h>
using namespace std;
int mp[5205][5205];
char s[5205][5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%s", s[i]);
    int ss = strlen(s[i]);
    for (int j = 0; j < ss; j++) {
      if (s[i][j] >= '0' && s[i][j] <= '9')
        a = s[i][j] - '0';
      else
        a = s[i][j] - 'A' + 10;
      for (int k = 1; k <= 4; k++) {
        mp[i + 1][j * 4 + 5 - k] = a % 2;
        a /= 2;
      }
    }
    for (int j = 0; j < n; j++) {
      mp[0][j] = -1;
      mp[j][0] = -1;
    }
  }
  for (int i = n; i >= 1; i--) {
    int flag = 1;
    if (n % i == 0) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (mp[j][k] != mp[j / i][k / i]) {
            flag = 0;
            break;
          }
          if (mp[j][k] != mp[j - 1][k] &&
              mp[j / i][k / i] == mp[(j - 1) / i][k / i]) {
            flag = 0;
            break;
          }
          if (mp[j][k] != mp[j][k - 1] &&
              mp[j / i][k / i] == mp[j / i][(k - 1) / i]) {
            flag = 0;
            break;
          }
        }
        if (flag == 0) break;
      }
      if (flag) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
