#!/usr/bin/env python
# coding: utf-8

# In[ ]:


n=int(input())
matrix=[]
for i in range(n):
    
    matrix.append(list(input()))

    #scale = 16 ## equals to hexadecimal

    #num_of_bits = n
    #matrix.append(list(bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)))


# In[ ]:


#print(matrix)


# In[ ]:


divisors=[]

for i in range(1,n+1):
    if n%i==0:
        divisors.append([i,0])

divisors.sort()        


# In[ ]:


gooddiv=[1]


# In[ ]:


for div, bad in divisors:
    if div==1:
        continue
    
    #print(divisors, div)
    if bad==1:
        continue
    #clist=[[[] for i in range(n//div)] for j in range(n//div)]
    
    for k in range(n//div):
        for m in range(n//div):
        
            hexvalue2=matrix[div*k][(div*m)//4]
        
            binlist2=list(bin(int(hexvalue2, 16))[2:].zfill(4))
        
            binvalue2=binlist2[(div*m)%4]
            for i in range(div):
                for j in range(div):
                    if i==0 and j==0:
                        #clist[i//div][j//div]=matrix[i][j]
                        continue
                    else:
                
                        hexvalue1=matrix[i][j//4]
                                                    
                        binlist1=list(bin(int(hexvalue1, 16))[2:].zfill(4))
                
                                    
                        binvalue1=binlist1[j%4]
                
                    
                
                        #print(binvalue1, binvalue2)
                
                        if not binvalue1==binvalue2:
                            bad=1
                            break
                
                if bad==1:
                    for p in divisors:
                        if p[0]%div==0:
                            p[1]=1
                    break
            
            if bad==1:
                break
                
        if bad==1:
            break
    if bad==0:
        gooddiv.append(div)
        
    #print(clist)    
gooddiv.sort()

print(gooddiv[-1])

