//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <string>
#include <map>
#include <set>
#include <list>
typedef long long ll;

using namespace std;
const double pi = acos(-1);
const ll maxn = 2e5+10;
const ll mxn = 5210;
const ll mo = 1e9 + 7;

ll i,j,n,m,k,len;

ll pm(ll x,ll y)
{
    ll res = 1;
    x %= mo;
    while(y)
    {
        if(y & 1)
            res = res * x % mo;
        y >>= 1;
        x = x * x % mo;
    }
    return res;
}
ll jl = 0,jr = 0;
ll a[mxn][mxn];
char s[mxn];

void dfs1(ll x,ll y,int k)
{
    if(a[x][y] != k)
        return;
    jl++;
    dfs1(x,y+1,k);
}
void dfs2(ll x,ll y,int k)
{
    if(a[x][y] != k)
        return;
    jr++;
    dfs2(x+1,y,k);
}

int main(){
    ll t,tt,p,cnt,ans = 0,len = 0;
    scanf("%lld",&n);
    len = n / 4;
    for(i = 0;i < n;i++)
    {
        scanf("%s",s);
        for(j = 0;j < len;j++)
        {
            ll tmp;
            if(s[j] > '9')
            {
                tmp = s[j] - 'A' + 10;
            }
            else
            {
                tmp = s[j] - '0';
            }
           // printf("%lld\n",tmp);
            for(k = j * 4 + 3;k >= j * 4;k--)
            {
                a[i][k] = tmp % 2;
                tmp /= 2;
            }
        }
    }
  /*  for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
        {
            printf("%lld",a[i][j]);
        }
        printf("\n");
    }*/
    ll l1 = 55555,r1 = 55555,l2 = 55555,r2 = 55555;
    for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
        {
            jr = 0,jl = 0;
            dfs1(i,j,a[i][j]);
           // dfs2(i,j,a[i][j]);
            if(a[i][j] == 1)
            {
                l1 = min(l1,jl);
            //    r1 = min(r1,jr);
            }
            else
            {
                l2 = min(l2,jl);
           //     r2 = min(r2,jr);
            }
            j = j + jl - 1;

        }
    }
    for(j = 0;j < n;j++)
    {
        for(i = 0;i < n;i++)
        {
            jr = 0,jl = 0;
            dfs2(i,j,a[i][j]);
           // dfs2(i,j,a[i][j]);
            if(a[i][j] == 1)
            {
             //   l1 = min(l1,jl);
                r1 = min(r1,jr);
            }
            else
            {
            //    l2 = min(l2,jl);
               r2 = min(r2,jr);
            }
            i = i + jr - 1;

        }
    }
    if(l1 == 55555)
    {
        l1 = l2;
    }
    else if(l2 == 55555)
    {
        l2 = l1;
    }

    if(r1 == 55555)
    {
        r1 = r2;
    }
    else if(r2 == 55555)
    {
        r2 = r1;
    }
   // printf("%lld %lld %lld %lld\n",l1,l2,r1,r2);
   // printf("123");
    ans = __gcd(__gcd(l1,l2),__gcd(r1,r2));
    printf("%lld\n",ans);
    return 0;
}
