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

public class D {
    static boolean[][] arr;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        arr = new boolean[N][N];
        for(int i = 0; i < N; i++) {
            char[] nextLine = scanner.next().toCharArray();
            for(int j = 0; j < N/4; j++) {
                int num = Integer.parseInt(Character.toString(nextLine[j]), 16);
                for(int k = 0; k < 4; k++) {
                    arr[i][(j*4)+3-k] = (num&(1<<k)) > 0;
                }
            }
        }
        boolean[] checked = new boolean[N+1];
        int ans = 1;
        for(int i = 2; i < N; i++) {
            if (N%i==0) {
                checked[i] = true;
                ans = Math.max(ans, checkFactor(N, i));
            }
        }
        out.println(ans);
        out.flush();
    }
    public static int checkFactor(int N ,  int f) {
        boolean[][] sat = new boolean[N][N];
        int ret = 1;
        for(int i = f; i <= N && N%i==0; i*=f) {
            for(int j = 0; j < N; j+= i) {
                //check if already computed
                for(int l = 0; l < N; l+= i) {
                    //if (i > f && sat[j][l] &&  sat[j][l+N/(i*f)] && sat[j+N/(i*f)][l]) sat[j][l] = true;
                    if (i > f) {
                        int temp = i/f;
                        for(int k = 0; k < i; k+=temp) {
                            for(int m = 0; m < i; m += temp) {
                                if (sat[j+k][l+m] = false) return ret;
                            }
                        }
                    }
                    else {
                        for (int k = 0; k < i; k++) {
                            for (int m = 0; m < i; m++) {
                                if (arr[j][l] != arr[j + k][l + m]) return ret;
                            }
                        }
                        sat[j][l] = true;
                    }
                }
            }
            ret = i;
        }
        return ret;
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}
