#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
//#define int long long
#define pii pair<int,int>
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
#define fr first
#define se second
#define mp make_pair
const int MOD=(int) 1e9+7;
const int inf=(int)1e17;
     
using namespace std;
     
    //custom hash for unordered map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
     
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

inline int binexp(int a,int b,int m)
{
    int res=1;
    a%=m;
    while(b)
    {
        if(b&1)
    	    res=(res*1ll*a)%m;
        a=(a*1ll*a)%m;
        b>>=1;
    }
    return res;
}
const int N = 4e5+5;
int bit[N], arr[N];
inline void update(int i, int v) {
	for(;i < N; i+=i & -i) {
		bit[i] += v;
	}
}
inline int query(int i) {
	int t = 0 ;
	for(; i; i -= i & -i) {
		t += bit[i];
	}
	return t;
}
int mat[6000][6000];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r",stdin);
    freopen("ot.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
    	string s;
    	cin >> s;
    	int c = 0;
    	for(auto &it : s) {
    		int num = 0;
    		if(it > '9') {
    			num = 10 + (it - 'A');
    		}
    		else {
    			num = it - '0';
    		}
    		for(int j = 0; j < 4; ++j) {
    			mat[i + 1][c + (4 - j)] = num % 2;
    			num /= 2;
    		}
    		c += 4;
    	}
    }
    for(int i = 1; i <= n; ++i) {
    	for(int j = 1; j <= n; ++j) {
    	//	cout << mat[i][j] << " ";
    		mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
    	}
    	//cout << "\n";
    }
    vector<int> v;
    for(int i = 1; i <= n; ++i) {
    	if(n % i == 0) {
    		v.push_back(i);
    	}
    }
    int lo = 0, hi = v.size() - 1, ans = -1;
    while(lo <= hi) {
    	int mid = (lo + hi) >> 1;
    	int f = 1;
    	for(int i = 1; i <= n; i += v[mid]) {
    		for(int j = 1; j <= n; j += v[mid]) {
    			int sum = mat[i + v[mid] - 1][j + v[mid] - 1] - mat[i - 1][j + v[mid] - 1] - mat[i + v[mid] - 1][j - 1] + mat[i - 1][j - 1];
    			if(v[mid] == 2) {
    				//cout << sum << " " << i << " " << j << "\n";
    			}
    			if(sum != 0 && sum != v[mid] * v[mid]) {
    				f = 0;
    				break;
    			}
    		}	
    	}
    	if(f) {
    		//cout << mid << "\n";
    		lo = mid + 1;
    		ans = v[mid];
    	}
    	else {
    	//	cout << v[mid] << "\n";
    		hi = mid - 1;
    	}
    }
    cout << ans;
 	return 0;
}