#include <bits/stdc++.h>
using namespace std;
int a[5206][5206], aux[5206][5206];
int n, sol, lg;
int cmmdc(int x, int y) {
  int r;
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
int main() {
  cin >> n;
  for (int l = 1; l <= n; l++)
    for (int c = 1; c <= n / 4; c++) {
      char chr;
      int val;
      cin >> chr;
      if (chr >= '0' and chr <= '9')
        val = chr - '0';
      else
        val = chr - 'A' + 10;
      for (int bit = 3; bit >= 0; bit--)
        a[l][4 * c - bit] = ((val & (1 << bit)) > 0);
    }
  sol = n;
  for (int l = 1; l <= n; l++) {
    lg = 1;
    for (int c = 2; c <= n; c++)
      if (a[l][c] == a[l][c - 1])
        lg++;
      else {
        lg = 1;
      }
  }
  for (int l = 1; l <= n; l++) {
    lg = 1;
    for (int c = 2; c <= n; c++)
      if (aux[l][c] == aux[l][c - 1])
        lg++;
      else {
        lg = 1;
      }
  }
  cout << 1;
  return 0;
}
