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

"""
import sys
from io import BytesIO, FileIO

sys.stdin = BytesIO(FileIO(0).read())
input = lambda: sys.stdin.readline().rstrip('\r\n')


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()
