#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


// #define forr(i,n) for(int i = 0 ; i  < n ; i++)
// #define forr1(i,n) for(int i = 1 ; i  <= n ; i++)
// #define int long long int
// #define pb push_back
// #define endl "\n"
// vector<vector<pair<int, int>>> graph ;
// vector<int> max_fuel;
// vector<bool> visit ;

const int inf = 1e9 + 32;
const int N = 5200;

int n;
bool a[N][N];

void parse_char(int x, int y, char c) {
    int num = -1;
    if (isdigit(c)) {
        num = c - '0';
    } else {
        num = c - 'A' + 10;
    }
    for (int i = 0; i < 4; ++i) {
        a[x][y + 3 - i] = num & 1;
        num >>= 1;
    }
}

int32_t main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    // freopen("output.txt" , "w" , stdout);
#endif

    
    cin >> n;
    char buf[N];
    for (int i = 0; i < n; ++i) {
        scanf("%s", buf);
        for (int j = 0; j < n / 4; ++j) {
            parse_char(i, j * 4, buf[j]);
        }
    }
    int g = n ;
    for (int i = 0 ; i <  n ; i++)
    {
        for (int j = 0 ; j < n ; j++)
        {
            int k = j ;
            while ( k < n && a[i][k] == a[i][j])k++ ;
            g = __gcd(g, k - j);
            j = k - 1;
        }
    }

    for (int i = 0 ; i <  n ; i++)
    {
        for (int j = 0 ; j < n ; j++)
        {
            int k = j ;
            while ( k < n && a[k][i] == a[j][i])k++ ;
            g = __gcd(g, k - j);
            j = k - 1;
        }
    }
    cout << g << endl;


}