n = int(input())
a = []
ma = -1
for _ in range(n):
	t = input()
	temp = list(str(bin(int(t, 16))))
	if(len(temp) > ma):
		ma = len(temp)
	a.append(temp[2:])

for i in range(n):
	temp = a[i]
	x = ma - len(temp)
	temp += '0'*x
	a[i] = temp
	print(''.join(a[i]))

div = []
for i in range(1, int(n**0.5) + 1):
	if(n % i == 0):
		if(n//i != i):
			div.append(i)
			div.append(n//i)
		else:
			div.append(i)

ma = 1
for k in range(len(div)):
	d = div[k]
	ans = True
	for i in range(0, n, d):
		for j in range(0, n, d):
			cur = a[i][j]
			for x in range(i, i + d):
				for y in range(j, j + d):
					if(a[x][y] != cur):
						ans = False
						break
	if(ans):
		if(d > ma):
			ma = d

print(ma)

