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

public class Main {


    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintStream out = System.out;
        TaskD taskD = new TaskD();
        taskD.solve(in, out);
    }

    static class TaskD {
        byte[][] matrix;
        int N;
        int[][] sums;

        int getNum(char hex) {
            return Character.isDigit(hex) ? hex - '0' : hex - 'A' + 10;
        }

        int getSum(int i1, int i2, int j1, int j2) {
            return sums[i2][j2] - (sums[i2][j1] + sums[i1][j2] - sums[i1][j1]);
        }

        void input(InputReader in) {
            N = in.nextInt();
            matrix = new byte[N][N];
            sums = new int[N][N];
            for (int i = 0; i < N; i++) {
                char[] line = in.next().toCharArray();
                int j = 0;
                for (char hex : line) {
                    int n = getNum(hex);
                    for (int k = 3; k >= 0; k--) {
                        matrix[i][j++] = (byte) ((n >> k) & 1);
                    }
                }
            }
        }

        void solve(InputReader in, PrintStream out) {
            input(in);
            for (int i = 0; i < N; i++) {
                if (i == 0) sums[0][i] = matrix[0][i];
                else sums[0][i] = sums[0][i-1] + matrix[0][i];
            }
            for (int i = 1; i < N; i++) {
                sums[i][0] = sums[i-1][0] + matrix[i][0];
            }
            for (int i = 1; i < N; i++) {
                for (int j = 1; j < N; j++) {
                    sums[i][j] = sums[i-1][j] + sums[i][j-1] - sums[i-1][j-1] + matrix[i][j];
                }
            }
            for (int x = N; x >= 1; x--) {
                if (N % x != 0) continue;
                boolean ok = true;
                for (int i = 0; i+x-1 < N; i += x) {
                    for (int j = 0; j+x-1 < N; j+= x) {
                        int sum = getSum(i, i+x-1, j, j+x-1);
                        if (sum != x*x && sum != 0) {
                            ok = false;
                            break;
                        }
                    }

                }
                if (ok) {
                    out.println(x);
                    return;
                }
            }
        }


    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        double nextDouble() {return Double.parseDouble(next());}
    }
}