#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <unordered_map>
#define P pair<LL, LL>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (LL i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
// #define inf 0x3f3f3f3f3f3f3f3f
// const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const LL MAX = 2e3 + 50;
#else
const int MAX = 2e3 + 50;
#endif
const int mod = 1e9 + 7;

char s[5500][5500];
char t[2000];
map<char, string> m;

int main(){
#ifdef DEBUG
	freopen("in", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	int nn = n / 4;
	for(int i = 1; i <= n; i++){
		scanf("%s", t+1);
		for(int j = 1; j <= nn; j++){
			int x;
			if(t[j] >= '0' and t[j] <= '9') x = t[j] - '0';
			else x = t[j] - 'A' + 10;
			for(int k = 3; k >= 0; k--){
				s[i][j*4+k-3] = x & 1;
				x >>= 1;
			}
		}
	}
	int g = -1, last = 1;
	for(int i = 1; i <= n; i++){
		last = 1;
		for(int j = 2; j <= n; j++){
			if(s[i][j] != s[i][j-1]){
				int len = i - last;
				g = g == -1 ? len : __gcd(g, len);
				last = i;
			}
		}
		g = g == -1 ? n+1-last : __gcd(g, n+1-last);
	}
	for(int j = 1; j <= n; j++){
		last = 1;
		for(int i = 2; i <= n; i++){
			if(s[i][j] != s[i-1][j]){
				int len = i-last;
				g = __gcd(g, len);
				last = i;
			}
		}
		g = __gcd(g, n+1-last);
	}
//	for(int i = 1; i <= n; i++){
//		for(int j = 1; j <= n; j++)
//			printf("%d%c", s[i][j], j == n ? '\n' : ' ');
//	}
	printf("%d\n", g);
	return 0;
}

		     		 	 	 	 	    	 	    			