import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class r59p3{

    private static InputReader sc;
    private static PrintWriter pw;
    private static boolean dp[];

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        InputReader(InputStream stream) {
            this.stream = stream;
        }

        int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);
        }
    }

    public static void main(String args[]) {
        sc = new InputReader(System.in);
        pw = new PrintWriter(System.out);

        int t = 1;
        while(t-->0)
            solve();

        pw.flush();
        pw.close();
    }

    private static int func(char k, int i){
        String s[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};

        if('0' <= k && k <= '9')
            return (int)s[(int)k-'0'].charAt(i)-'0';
        else
            return (int)s[((int)k-'A')+10].charAt(i)-'0';
    }

    private static int cal(char grid[][], int i, int j){
        return func(grid[i][j/4], j%4);
    }

    private static void solve(){

        int n = sc.nextInt();

        char grid[][] = new char[n][n/4];
        for(int i=0; i<n; i++)
            grid[i] = sc.readString().toCharArray();

        //System.out.println('d');

        dp = new boolean[n+1];
        dp[1] = true;

        for(int i = 2; i <= n; i+=2){
            if (n % i == 0) {
                for(int j = i-1; j >= 1; j--){
                    if(i % j == 0){
                        dp[i] = dp[j] && check(grid, i, j, n);
                        break;
                    }
                }
            }
            else
                dp[i] = false;
        }

        char k = grid[0][0];

        if(k == 'F' || k == '0') {
            dp[n] = true;
            outer: for (int i = 0; i < n; i++) {
                for (int j = 0; j < n / 4; j++) {
                    if (grid[i][j] != k) {
                        //System.out.println(i+" "+j);
                        dp[n] = false;
                        break outer;
                    }
                }
            }
        }

        for(int i=n; i>=1; i--){
            if(dp[i]) {
                pw.println(i);
                break;
            }
        }
    }

    private static boolean check(char grid[][], int i, int j, int n){

        //System.out.println(i+" "+j);
        int temp[][] = new int[i][i];
        for(int p = 0; p < n; p += i){
            for(int q = 0; q < n; q += i){
                for(int a = 0; a < i; a++){
                    for(int b = 0; b < i; b++)
                        temp[a][b] = cal(grid, a+p, b+q);
                }
                if(!risk(temp, j, i))
                    return false;
            }
        }

        return true;
    }

    private static boolean risk(int temp[][], int j, int i){
        int t = temp[0][0];

        for(int p = 0; p < i; p += j){
            for(int q = 0; q < i; q += j)
                if(temp[p][q] != t)
                    return false;
        }
        return true;
    }
}