#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int a[5300][5300], b[5300][5300];
vi v;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		if(n % i ==0)
			v.pb(i);
	}
	for(int i = 1; i <= n; i ++)
	{
		string s;
		cin >> s;
		for(int j = 0; j < s.size(); j ++)
		{
			int x = (s[j] >= 'A' ? s[j] - 'A' + 10 : s[j] - 48);
			int id = (j+1)*4;
			while(x > 0)
			{
			a[i][id --] = x%2;
			x /= 2;
			}
		}
	}
	set<int> s;
	for(int i = 1; i <= n; i ++)
	for(int j = 1; j <= n; j ++)
		s.insert(a[i][j]);
		if(s.size() == 1)
			cout << n;
		else
			cout << 1;
		return 0;
	reverse all(v);
	for(auto it : v)
	{
		for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			b[i][j] = -1;
		int flag = 0, x = it;
		for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= n; j ++)
		{
				if(b[i/x+(i%x!=0)][j/x+(j%x!=0)] == -1 || b[i/x+(i%x!=0)][j/x+(j%x!=0)] == a[i][j])
				{
					b[i/x+(i%x!=0)][j/x+(j%x!=0)] = a[i][j];
				}
				else
				{
					flag = 1;
					break;
				}
		}
		if(flag)
			break;
		}
		if(!flag)
			return cout << it, 0;
	}
	/*
	for(int i = 1; i <= n; i ++)
	for(int j = 1; j <= n; j ++)
		cin >> a[i][j];
	int x;
	cin >> x;
	for(int i = 1; i <= n  * x; i ++)
	for(int j = 1; j <= n * x; j ++)
		if(i > n || j > n)
		a[i][j] = (a[i/x+(i%x!=0)][j/x+(j%x!=0)]);
	for(int i = 1; i <= n * x; i ++, cout << '\n')
	for(int j = 1; j <= n*x; j ++)
		cout << a[i][j] << ' ';
	*/




	





	getchar();
	getchar();
	return 0;
}