#include <bits/stdc++.h>
using namespace std;
const int N = 5205;
int n;
char str[N];
int store[16][4];
int integer(char ch) {
  if (isdigit(ch))
    return ch - '0';
  else
    return ch - 'A' + 10;
}
void preprocess() {
  for (int i = 0; i < 16; i++) {
    int temp = i, pt = 3;
    while (temp > 0) {
      int r = temp % 2;
      store[i][pt--] = r;
      temp /= 2;
    }
  }
}
int ara[N][N];
int dp[N][N];
void load() {
  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] + ara[i][j];
    }
  }
}
int compute(int x1, int y1, int x2, int y2) {
  int ans = dp[x2][y2] - dp[x2][y1 - 1] - dp[x1 - 1][y2] + dp[x1 - 1][y1 - 1];
  return ans;
}
int main() {
  preprocess();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    int pt = 1;
    for (int j = 0; j < n / 4; j++) {
      int d = integer(str[j]);
      for (int k = 0; k < 4; k++) {
        ara[i + 1][pt++] = store[d][k];
      }
    }
  }
  load();
  int ans = dp[n][n];
  int total = n * n;
  if (ans == 0 or ans == total)
    printf("%d\n", n);
  else
    printf("1\n");
}
