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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            Debug debug = new Debug();
            int n = in.nextInt();
            char[][] map = new char[n + 1][n + 1];

            for (int i = 1; i <= n; ++i) {
                char[] s = in.nextString().toCharArray();
                for (int j = 0; j < s.length; ++j) {
                    char[] bin = getValue(s[j]);
                    for (int k = 4 * j + 1; k < 4 * (j + 1) + 1; ++k) {
                        map[i][k] = bin[(k - 1) % 4];
                    }
                }
            }
            int[] divs = getDivisor(n);

            int low = -1;
            int high = divs.length;
            while (high - low > 1) {
                int mid = (high + low) >>> 1;
                if (possible(map, divs[mid], n)) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            out.println(low + 1);
        }

        private boolean possible(char[][] map, int div, int n) {
            char[][] mn = new char[n / div + 1][n / div + 1];
            ArrayUtils.fill(mn, ',');
            for (int i = 1; i <= n; ++i) {
                for (int j = 1; j <= n; ++j) {
                    int r = (i + div - 1) / div;
                    int c = (j + div - 1) / div;
                    if (mn[r][c] == ',') {
                        mn[r][c] = map[i][j];
                    } else if (mn[r][c] != map[i][j]) {
                        return false;
                    }
                }
            }
            return true;
        }

        private int[] getDivisor(int n) {
            int[] a = new int[10000];
            int ptr = 0;
            for (int i = 1; i <= n; ++i) if (n % i == 0) a[ptr++] = i;
            return Arrays.copyOf(a, ptr);
        }

        private char[] getValue(char c) {
            int value = 0;
            if (c >= 'A') {
                value = 10 + (c - 'A');
            } else {
                value = c - '0';
            }
            String bi = Integer.toBinaryString(value);
            while (bi.length() < 4) bi = "0" + bi;
            return bi.toCharArray();
        }

    }

    static class ArrayUtils {
        public static void fill(char[][] array, char value) {
            for (char[] row : array) {
                Arrays.fill(row, value);
            }
        }

    }

    static class Debug {
        PrintWriter out;
        boolean oj;
        long timeBegin;
        Runtime runtime;

        public Debug(PrintWriter out) {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            this.out = out;
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

        public Debug() {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            OutputStream outputStream = System.err;
            this.out = new PrintWriter(outputStream);
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

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

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

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

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

    }
}

