#include <bits/stdc++.h>
using namespace std;
vector<string> a;
int b[6 * 1005][6 * 1005];
char s[2000];
class Solution {
 public:
  string bin(char c) {
    if (c == '0')
      return "0000";
    else if (c == '1')
      return "0001";
    else if (c == '2')
      return "0010";
    else if (c == '3')
      return "0011";
    else if (c == '4')
      return "0100";
    else if (c == '5')
      return "0101";
    else if (c == '6')
      return "0110";
    else if (c == '7')
      return "0111";
    else if (c == '8')
      return "1000";
    else if (c == '9')
      return "1001";
    else if (c == 'A')
      return "1010";
    else if (c == 'B')
      return "1011";
    else if (c == 'C')
      return "1100";
    else if (c == 'D')
      return "1101";
    else if (c == 'E')
      return "1110";
    else if (c == 'F')
      return "1111";
  }
  bool can(int x) {
    int n = (int)a[1].size() - 1;
    for (int i = 1; i <= n / x; i++) {
      for (int j = 1; j <= n / x; j++) b[i][j] = -1;
    }
    for (int y = 1; y <= n; y++) {
      for (int z = 1; z <= n; z++) {
        int i = ((y + x - 1) / x);
        int j = ((z + x - 1) / x);
        if (b[i][j] == -1) {
          b[i][j] = (a[z][y] - '0');
        } else if (b[i][j] != (a[z][y] - '0'))
          return false;
        else
          continue;
      }
    }
    return true;
  }
  void solve(std::istream& in, std::ostream& out) {
    int n;
    scanf("%d", &n);
    a.resize(n + 1);
    scanf("%s", s);
    for (int i = 1; i <= n; i++) {
      scanf("%s", s);
      a[i] += ' ';
      for (int j = 0; j <= n / 4 - 1; j++) {
        a[i] += bin(s[j]);
      }
    }
    int sq = (int)ceil(sqrt(1.0 * n));
    int mx = -1;
    for (int i = 1; i <= sq; i++) {
      if (n % i == 0) {
        int x1 = i;
        int x2 = n / i;
        if (can(x1)) mx = max(mx, x1);
        if (can(x2)) mx = max(mx, x2);
      }
    }
    printf("%d", mx);
    return;
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
