#include <bits/stdc++.h>
using namespace std;
vector<int> getDivisors(int n) {
  vector<int> divisors;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      divisors.push_back(i);
    }
  }
  return divisors;
}
int getDecimalValue(char ch) {
  if (ch >= '0' && ch <= '9') {
    return ch - '0';
  } else {
    return 10 + (ch - 'A');
  }
}
string getBinaryValue(int n) {
  string result = "";
  bitset<4> tmp(n);
  return tmp.to_string();
}
bool isValid(vector<vector<int> >& counts, int n) {
  for (int i = 0; i < counts.size(); i += n) {
    for (int j = 0; j < counts.size(); j += n) {
      int current = counts[i + n - 1][j + n - 1];
      if (i > 0) {
        current -= counts[i - 1][j + n - 1];
      }
      if (j > 0) {
        current -= counts[i + n - 1][j - 1];
      }
      if (i > 0 && j > 0) {
        current += counts[i - 1][j - 1];
      }
      if (current == n * n || current == 0) {
        continue;
      }
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<vector<bool> > data(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      string binary = getBinaryValue(getDecimalValue(s[j]));
      for (int k = 0; k < binary.size(); k++) {
        data[i][j * binary.size() + k] = (binary[k] - '0') == 0;
      }
    }
  }
  vector<vector<int> > counts(n, vector<int>(n, 0));
  counts[0][0] = data[0][0];
  for (int i = 1; i < n; i++) {
    counts[0][i] = counts[0][i - 1] + data[0][i];
  }
  for (int i = 1; i < n; i++) {
    counts[i][0] = counts[i - 1][0] + data[i][0];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      counts[i][j] = counts[i - 1][j] + counts[i][j - 1] -
                     counts[i - 1][j - 1] + data[i][j];
    }
  }
  vector<int> divisors = getDivisors(n);
  int result = 1;
  for (int i = 1; i < divisors.size() - 1; i++) {
    if (isValid(counts, divisors[i])) {
      result = max(result, divisors[i]);
    }
  }
  cout << result << endl;
  return 0;
}
