#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <tr1/unordered_map>
#include <cmath>
#include <map>
#include <bitset>
#include <set>
#include <iomanip>
#include <utility>    
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector< ii > vii;
#define ALL(x) (x).begin(),x.end()
#define CLEAR0(v) memset(v, 0, sizeof(v))
#define CLEAR(v, x) memset(v, x, sizeof(v))
#define COPY(a, b) memcpy(a, b, sizeof(a))
#define CMP(a, b) memcmp(a, b, sizeof(a))
#define REP(i,n) for(int i = 0; i<n; i++)
#define REPP(i,a,n) for(int i = a; i<n; i++)
#define REPD(i,n) for(int i = n-1; i>-1; i--)
#define REPDP(i,a,n) for(int i = n-1; i>=a; i--)

int n;
string s, c;

bitset<5300> m[5300];

int ac[5300][5300];

void precalc(){
	REP(i, n+1){ ac[0][i] = 0; ac[i][0] = 0; }
	REP(i, n){
		REP(j, n) ac[i+1][j+1] = ac[i+1][j] + ac[i][j+1] - ac[i][j] + m[i][j];
	}
}

int sum(int l, int r, int u, int d){ //1-based
	return ac[d][r] - ac[d][l-1] - ac[u-1][r] + ac[u-1][l-1];
}

bool isOk(int l, int r, int u, int d){
	int val = sum(l, r, u, d);
	//cout << " L " << l << " R " << r << " U " << u << " D " << d << endl;
	//cout << val << endl;
	return val == 0 || val == (r-l+1) * (d-u+1);
}

bool can(int x){
	REP(i, n/x){
		REP(j, n/x){
			bool ok = isOk(i*x+1, (i+1)*(x), j*x+1, (j+1)*x);
			if(!ok) return false;
		}
	}
	return true;
}

int solve(){
	precalc();
	int ans = 1;
	REPP(i, 2, n+1){
		if((i%n == 0) && can(i)){
			ans = i;
		}
	}
	return ans;
}

void print(){
	REP(i, n){
	REP(j, n) cout << m[i][j]; cout << endl;}
	precalc();

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	stringstream ss;
	REP(i, n){
		cin >> s;
		//cout << "S " << s << endl;
		REP(j, s.length()){
			c = "0x" + string(1, s[j]);
			ss << hex << c;
			int n;
			ss >> n;
			REP(k, 4){
				m[i][j * 4 + k] = ((n&(1 << k)) != 0);
			}
			//cout << " N " << n << endl;
		}
	}
	cout << solve() << endl;	
	
}
