
import java.io.*;
import java.util.*;

public class Test
{
    static PrintWriter pw = new PrintWriter(System.out);

    static boolean can(int m , byte[][] a , int n)
    {
        int x1 = 0 , y1 = m-1;
        for(int i = 0 ; i<n/m ; i++)
        {
            int x2 = 0 , y2 = m-1;
            for(int j=0; j<n/4 ; j++)
            {
                if(!cheack(x1,y1,x2,y2,a))return false;

                x2 += m;
                y2 += m;
            }


            x1 += m;
            y1 += m;
        }
        return true;
    }

    static boolean cheack(int x1 , int y1 , int x2 , int y2 , byte[][] a)
    {
        byte t = -1;
        for(int i = x1; i<=x2 ; i++)
            for(int j = x2 ; j<=y2 ; j++)
                if(t == -1)t = a[i][j];
                else if(t != a[i][j])return false;


        return true;

    }

    public static void main(String[] args) throws Exception
    {
        Reader.init(System.in);
        String[] str = {"0000" , "0001" , "0010" , "0011", "0100" ,"0101" ,"0110" ,
                "0111" , "1000" , "1001" , "1010" , "1011", "1100" , "1101" , "1110" , "1111"};
        int n = Reader.nextInt();
        ArrayList<Integer> list = new ArrayList();
        byte[][] a = new byte[n][n];


        for(int i = 0 ; i<n ; i++)
        {
            String s = Reader.next();
            int ind  = 0;
            for(int j = 0 ; j<n/4 ; j++)
            {
                char c = s.charAt(j);
                String x = "";
                if(c >='0' && c<= '9')x = str[c - '0'];
                else x = str[10 + c - 'A'];

                for(int q = 0 ; q<4 ; q++ , ind++)a[i][q] = (byte)(x.charAt(q) - '0');
            }

        }

        int sq = (int)Math.sqrt(n);
        for(int i = 1 ; i<=sq ; i++)
            if(n % i == 0)
            {
                list.add(i);
                if(n/i != i)list.add(n/i);
            }

        Collections.sort(list);

        int L = 0 , R = list.size()-1;
        int res = 0;
        while(L<=R)
        {
            int m = (L+R)/2;
            if(can(list.get(m) , a , n))
            {
                res = list.get(m);
                L = m+1;
            }
            else R = m-1;
        }


        pw.print(res);
        pw.close();
    }


}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}