#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int>> g(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int tmp = 0;
		for (int j = 0; j < (int) s.length(); j++) {
			tmp = tmp * 16 + (s[j] >= 'A' ? s[j] - 'A' + 10 : s[j] - '0');
		}
		for (int j = 0; j < n; j++) {
			g[i][j] = tmp % 2;
			tmp /= 2;
		}
	}
	int ans = n;
	for (int i = 0; i < n; i++) {
		int cnt = 1;
		for (int j = 1; j < n; j++) {
			if (g[i][j] == g[i][j - 1]) cnt++;
			else {
				ans = __gcd(ans, cnt);
				cnt = 1;
			}
		}
	}
	for (int j = 0; j < n; j++) {
		int cnt = 1;
		for (int i = 1; i < n; i++) {
			if (g[i][j] == g[i - 1][j]) cnt++;
			else {
				ans = __gcd(ans, cnt);
				cnt = 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}