ans=0
def string(s,n):
  j=''
  for i in range(n//4):
    if s[i]=='0' :
      j=j+'0000'
    if s[i]=='1' :
      j=j+'0001'
    if s[i]=='2' :
      j=j+'0010' 
    if s[i]=='3' :
      j=j+'0011' 
    if s[i]=='4' :
      j=j+'0100' 
    if s[i]=='5' :
      j=j+'0101'
    if s[i]=='6' :
      j=j+'0110'
    if s[i]=='7' :
      j=j+'0111'
    if s[i]=='8' :
      j=j+'0100'
    if s[i]=='9' :
      j=j+'0101'
    if s[i]=='A' :
      j=j+'1010'
    if s[i]=='B' :
      j=j+'1011'
    if s[i]=='C' :
      j=j+'1100'
    if s[i]=='D' :
      j=j+'1101'
    if s[i]=='E' :
      j=j+'1110'
    if s[i]=='F' :
      j=j+'1111'     
  return j                                        
def check(s,i):
  for j in range(len(s)):
    ans1=0
    if j==0 or j%i==0:
      continue
    else:
      if  s[j]!=s[j-1]:
        ans1=1
        break 
  return ans1      
n=int(input(''))
divi=[]
a=[]
x=1

for i in range(n):
  if n%(i+1)==0:
    divi.append(i+1)
  s=input('')
  a.append(s)
j=0  
for i in range(1,len(divi)):
  for j in range(len(a)):
    if j%divi[i]==0:
      jj=string(a[j],n)
      ans=check(jj,divi[i])
      j+=1
    if ans ==0:
      if a[j]!=a[j-1]:
        ans=1
        break
  if ans==0: 
    x=divi[i]
  if ans==1:
    break
print(x)           


      


 

 