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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front;
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(j,a,b) for(int j=a;j<=b;j++)
#define mem(x,a) memset(x,a,sizeof(x))

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef map<ll,ll> spt;
typedef set<ll> si;
typedef multiset<ll>::iterator sit;
typedef map<int,int>::iterator mi;
typedef vector<int>::iterator vit;
typedef vector<ii> vii;
typedef set<ii> sii;
typedef multiset<ll> msi;
typedef vector< vector<ll> > matrix;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ost1;
int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; }
string tostring ( int number ){  stringstream ss; ss<< number; return ss.str();}
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5  ;
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

unordered_map<char,string> gm;
string s[5201];
ll sum[5201][5201];

void func(ll n){
	for(int i=0;i<n;i++){
		ll tot=0;
		for(int j=0;j<n;j++){
			tot+=(s[i][j]-'0');
			sum[i+1][j+1]=tot;
		}
	}
	for(int j=1;j<=n;j++){
		ll tot=0;
		for(int i=1;i<=n;i++){
			tot+=sum[i][j];
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	ll n;
	cin>>n;
	gm['0']="0000";
	gm['1']="0001";
	gm['2']="0010";
	gm['3']="0011";
	gm['4']="0100";
	gm['5']="0101";
	gm['6']="0110";
	gm['7']="0111";
	gm['8']="1000";
	gm['9']="1001";
	gm['A']="1010";
	gm['B']="1011";
	gm['C']="1100";
	gm['D']="1101";
	gm['E']="1110";
	gm['F']="1111";
	rep(i,n){
		char c;
		rep(j,n/4){
			cin>>c;
			s[i]+=gm[c];
		}
	}
	func(n);
	for(int i=n;i>0;i--){
		if(n%i)
			continue;
		ll flag=0;
		for(int j=1;j<=n;j+=i){
			for(int k=1;k<=n;k+=i){
				ll temp=sum[j+i-1][k+i-1]-sum[j+i-1][k-1];
				if(temp==0||(temp>0&&temp==i*i))
					continue;
				else
					flag=1;
			}
		}
		if(!flag){
			cout<<i;
			break;
		}
	}
}
