//by Top1
#include <bits/stdc++.h>
     
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
#define pi 3.1415926535      

//const int inf = (1e18) + 1;
const int mod = 998244353 ;
const int mod2 = 998244353 ;
const int maxn = 2e5 + 111;
const int N = 1e6;        
using namespace std;                                                                               

//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

int n;
char a[5200][1400];

void solve(){
	cin >> n;
	
	set <char> s;
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j * 4 <= n; j++)
			cin >> a[i][j], s.insert(a[i][j]);
			
	int x = 4;
	for (auto i : s){
		if (i == '0' || i == 'F')
			continue;
		else if (i == '3' || i == 'C')
			x = 2;
		else{
			cout << 1;
			return;
		}
	}
	if (x == 2){
		for (int i = 1; i <= n; i += x){
			for (int j = 1; j * 4 <= n; j++){
				for (int k = i; k < i + x - 1; k++)
					if (a[k][j] != a[k + 1][j]){
						cout << "1";
						return;
					}
			}
		}
		cout << x;
		return;
	}
	
	int ans = 1;
	
	for (int q = 4; q <= n; q += 4){
		if (n % q != 0)
			continue;
		bool ch = true;
		for (int i = 1; i <= n; i += q){
			for (int j = 1; j * 4 <= n; j += q / 4){
				s.clear();
				for (int x = i; x < i + q; x++){
					for (int y = i; y < j + q / 4; y++){
						s.insert(a[x][y]);
						if (sz(s) > 1){
							ch = false;
							break;
						}
					}
					if (!ch)
						break;
				}
				if (!ch)
					break;
			}
			if (!ch)
				break;
		}
		if (ch)
			ans = q;
	}
	
	cout << ans << endl;
}

main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	                                            	
    boost;	

    int qq = 1;
	
   	//cin >> qq;
      
    while (qq--){
        solve();
    }
}