#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
import os
from atexit import register
from io import BytesIO

stdout = BytesIO()
register(lambda: os.write(1, stdout.getvalue()))

readline = BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = lambda: readline().decode().rstrip('\r\n')


def print(*args, sep=' ', end='\n'):
    stdout.write(sep.join(map(str, args)).encode())
    stdout.write(end.encode())


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    n = int(input())
    mat = [format(int(input(), 16), '0%db' % n) for _ in range(n)]

    t = [0] * (n + 1)

    for i in range(n):
        cnt1, cnt2 = 1, 1
        prev1, prev2 = mat[i][0], mat[0][i]

        for j in range(1, n):
            if mat[i][j] == prev1:
                cnt1 += 1
            else:
                t[cnt1], cnt1 = 1, 1

            if mat[j][i] == prev2:
                cnt2 += 1
            else:
                t[cnt2], cnt2 = 1, 1

            prev1, prev2 = mat[i][j], mat[j][i]

        t[cnt1], t[cnt2] = 1, 1

    res = n
    for i in range(n):
        if t[i] == 1:
            res = gcd(i, res)

    print(res)


if __name__ == '__main__':
    main()
