from sys import stdin
import math
n = int(input())
matrix = stdin.read().splitlines()
# print(n)
# print(matrix)
grid = [bin(int(i, 16))[2:] for i in matrix]
for i in range(n):
    if len(grid[i]) < n:
        grid[i] = ''.join(['0'] * (n - len(grid[i])) + list(grid[i]))
# print(grid)

ans = 1


def good(grid, a):

    # l = n // a
    for y in range(0, n, a):
        for x in range(0, n, a):
            t = grid[y][x]
            for i in range(a):
                for j in range(a):
                    if grid[y + i][x + j] != t:
                        return False
    return True


for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        x = n // i
        if good(grid, x):
            ans = x
            break
print(ans)