#include <bits/stdc++.h>
using namespace std;
int a[5205][5205];
int dp[5205][5205];
int main() {
  char str[5202];
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    int cnt = 1;
    for (int j = 0; str[j]; j++) {
      int tmp;
      if (str[j] >= '0' && str[j] <= '9')
        tmp = str[j] - '0';
      else
        tmp = 10 + str[j] - 'A';
      for (int k = 3; k >= 0; k--) {
        a[i][cnt++] = (tmp >> k) & 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
    }
  }
  int ans = 1;
  set<int> tmp;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      tmp.insert(i);
      tmp.insert(n / i);
    }
  }
  for (auto it = tmp.rbegin(); it != tmp.rend(); it++) {
    ans = *it;
    int flag = 0;
    for (int i = 1; i <= n / ans; i++) {
      if (flag) break;
      for (int j = 1; j <= n / ans; j++) {
        int x = i * ans;
        int y = i * ans;
        if (dp[x][y] - dp[x - ans][y] - dp[x][y - ans] + dp[x - ans][y - ans] ==
                0 ||
            dp[x][y] - dp[x - ans][y] - dp[x][y - ans] + dp[x - ans][y - ans] ==
                ans * ans) {
        } else {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0) {
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
