import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;


public class D {
    public static void main(String[] args) throws IOException {
        init(System.in);

        int n = nextInt();

        boolean[][] ar = new boolean[n][n];


        long l = System.currentTimeMillis();

        for (int i = 0; i < n; i++) {
            String str = next();

            for (int j = 0; j < n / 4; j++) {

                String hex = str.substring(j, j + 1);

                String bin = String.format("%4s", new BigInteger(hex, 16).toString(2)).replace(' ', '0');

                for (int k = 0; k < 4; k++) {
                    ar[i][j * 4 + k] = bin.charAt(k) == '1';
                }
            }
        }

        System.out.println(System.currentTimeMillis() - l);

        HashSet<Integer> consec = new HashSet<>();

        for (int i = 0; i < n; i++) {
            boolean last = ar[i][0];
            int curr = 1;
            for (int j = 1; j < n; j++) {
                if (ar[i][j] == last)
                    curr++;
                else {
                    consec.add(curr);
                    curr = 1;
                    last = ar[i][j];
                }
            }
            consec.add(curr);
        }

        for (int i = 0; i < n; i++) {
            boolean last = ar[0][i];
            int curr = 1;
            for (int j = 1; j < n; j++) {
                if (ar[j][i] == last)
                    curr++;
                else {
                    consec.add(curr);
                    curr = 1;
                    last = ar[j][i];
                }
            }
            consec.add(curr);
        }

        int ans = 0;

        for(int i : consec)
            ans = gcd(ans, i);

        System.out.println(ans);

    }

    static int gcd(int a, int b) {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a - b, b);
        return gcd(a, b - a);
    }

    /**
     * buffered reading int and double values
     */
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

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


