

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * http://codeforces.com/contest/1107/problem/D
 */
public class D {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            StringTokenizer nk = new StringTokenizer(reader.readLine());
            int n = parseInt(nk.nextToken());
            int[][] a = new int[n][n];
            int[][] sum = new int[n + 1][n + 1];
            for (int i = 0; i < a.length; i++) {
                char[] row = reader.readLine().toCharArray();
                for (int j = 0; j < row.length; j++) {
                    char c = row[j];
                    int val = parseInt(Character.toString(c), 16);
                    for (int r = 0; r < 4; r++) {
                        a[i][j * 4 + r] = (val & 1 << (3 - r)) >>> (3 - r);
                    }
                }
            }
            int lo = 1;
            int hi = n;
            int mid = lo;
            while (lo <= hi) {
                mid = lo + (hi - lo) / 2;
                if (can(a, mid)) {
                    lo = mid + 1;
                } else {
                    hi = mid - 1;
                }
            }
            System.out.println(mid);

        }
    }

    private static boolean can(int[][] a, int x) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i][j] != a[i / x][j / x]) {
                    return false;
                }
            }
        }
        return true;
    }
}