
import java.util.*;
 
import java.io.*;
import static java.lang.Double.max;
import static java.lang.Double.min;
 
 
public class Main {
    static FastReader in=new FastReader();
    static long  n,m,a=0,b=0,ans=1,SUM;
    static String S,St;
    public static void main(String [] args) {
       
    int n=in.nextInt(),a=0;
    int A[][]=new int[n][n];
    for(int i=0;i<n;i++){
    S=in.next();
    for(int u=0;u<S.length();u++){
    int x=S.charAt(u);
    if(x>60){x-='A';
    x+=10;}
    else x-='0';
    if((x&8)>0){A[i][a]++;}a++;
    if((x&4)>0){A[i][a]++;}a++;
    if((x&2)>0){A[i][a]++;}a++;
    if((x&1)>0){A[i][a]++;}a++;
    }
    a=0;}
    for(int i=1;i<n;i++){
    if(A[0][i]==A[0][i-1])ans++;
    else break;
    }
    for(int i=0;i<n;i++){
    for(int u=1;u<n;u++){
    b++;
    if(A[i][u]!=A[i][u-1]){
    if(b!=ans&&b%ans!=0&&ans%b!=0){System.out.println(1);return;}
    ans=(long) min(ans,b);
    b=0;
    
    }}}
    b=0;
    a=1;
    for(int i=1;i<n;i++){
    if(A[i][0]==A[i-1][0])a++;
    else break;
    }
    for(int u=0;u<n;u++){
    for(int i=1;i<n;i++){
    b++;
    if(A[i][u]!=A[i-1][u]){
    if(b!=a&&b%a!=0&&a%b!=0){System.out.println(1);return;}
    ans=(long) min(a,b);
    b=0;
    }}}
    b=gcd(a, (int) ans);
        System.out.println(b);
    }
    static int gcd(int a,int b){
    if(b==0){return a;}
    return gcd(b,a%b);
    }
    
    }
     
class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
}
 
class Sorting{
 
 public static int[] bucketSort(int[] array, int bucketCount) {
 
 if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
 
 if (array.length <= 1) return array; //trivially sorted
 
 
 
 int high = array[0];
 
 int low = array[0];
 
 for (int i = 1; i < array.length; i++) { //find the range of input elements
 
 if (array[i] > high) high = array[i];
 
 if (array[i] < low) low = array[i];
 
 }
 
 double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
 
 
 ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
 
 for (int i = 0; i < bucketCount; i++) { //initialize buckets
 
 buckets[i] = new ArrayList();
 
 }
 
 
 
 for (int i = 0; i < array.length; i++) { //partition the input array
 
 buckets[(int)((array[i] - low)/interval)].add(array[i]);
 
 }
 
 
 int pointer = 0;
 
 for (int i = 0; i < buckets.length; i++) {
 
 Collections.sort(buckets[i]); //mergeSort
 
 for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
 
 array[pointer] = buckets[i].get(j);
 
 pointer++;
 
 }
 
}
 
return array;
 
}
 
}