#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int A[5205][5205];
int memo[5205];
int chk[5205];
void read() {
    cin >> n;
    int row;
    for(int i = 1; i <= n; i++) {
        cin >> hex >> row;
        for(int j = 1; j <= n; j++) {
            A[i][j] = ((row & (1 << (n - j))) != 0);
        }
    }
}
int check(int i) {
    if(chk[i] != -2) return chk[i];
    int sample = A[i][1];
    for(int j = 1; j <= i; j++) {
        if(A[j][i] != sample || A[i][j] != sample)
            return chk[i] = -1;
    }
    return chk[i] = sample;
}
int dp(int i)   // 1 <= i <= n
{
    if(i <= 1) return i;
    if(memo[i]!= -1) return memo[i];
    int k = check(i);
    if(k == -1) return memo[i] = 1;
    int j = i;
    int cnt = 0;
    while(j>=1) {
        if(check(j) == k) {
            cnt++;
        } else {
            break;
        }
        j--;
    }
    int ans = 1;
    for(int j = 1; j <= cnt; j++) {
        ans = max(ans, __gcd(dp(i - j), j ));
    }
    return memo[i] = ans;
}
int main() {
    read();
    for(int i = 1; i <= n; i++)
        chk[i] = -2;
    memset(memo, -1 , sizeof(memo));
    cout << dp(n);
}
