#include <bits/stdc++.h>
using namespace std;
string getHex(char hexdec) {
  string st = "";
  switch (hexdec) {
    case '0':
      st = "0000";
      break;
    case '1':
      st = "0001";
      break;
    case '2':
      st = "0010";
      break;
    case '3':
      st = "0011";
      break;
    case '4':
      st = "0100";
      break;
    case '5':
      st = "0101";
      break;
    case '6':
      st = "0110";
      break;
    case '7':
      st = "0111";
      break;
    case '8':
      st = "1000";
      break;
    case '9':
      st = "1001";
      break;
    case 'A':
      st = "1010";
      break;
    case 'B':
      st = "1011";
      break;
    case 'C':
      st = "1100";
      break;
    case 'D':
      st = "1101";
      break;
    case 'E':
      st = "1110";
      break;
    case 'F':
      st = "1111";
      break;
  }
  return st;
}
vector<int> printDivisors(int n) {
  vector<int> v;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (n / i != i) v.push_back(n / i);
    }
  }
  sort(v.begin(), v.end());
  return v;
}
int main() {
  int n;
  cin >> n;
  bool arr[n + 1][n + 1];
  string st;
  string temp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j += 4) {
      int scan;
      bitset<4> bits;
      scanf("%1x", &scan);
      bits = bitset<4>(scan);
      for (int w = 3, v = 0; w >= 0; w--, v++) arr[i + 1][j + v + 1] = bits[w];
    }
  }
  int maxi = 1;
  vector<int> divi = printDivisors(n);
  int low = 1;
  int high = divi.size() - 1;
  while (low <= high) {
    int mid = (low + high) / 2;
    int sq = divi[mid];
    bool bb = true;
    for (int i = 1; i <= n && bb == true; i = i + sq) {
      for (int j = 1; j <= n && bb == true; j = j + sq) {
        for (int p = 0; p < sq && bb == true; p++) {
          for (int q = 0; q < sq && bb == true; q++) {
            if (arr[i + p][j + q] != arr[i][j]) {
              bb = false;
            }
          }
        }
      }
    }
    if (bb == true) {
      maxi = max(maxi, sq);
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << maxi << endl;
  return 0;
}
