import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Compression {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int x = 1;
        List<List<Boolean>> lastNums = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            boolean[] nextRow = new boolean[n];
            char[] nl = br.readLine().toCharArray();
            for (int j = 0; j < n / 4; j++) {
                switch (nl[j]) {
                    case '1':
                        nextRow[j * 4] = true;
                        break;
                    case '2':
                        nextRow[j * 4 + 1] = true;
                        break;
                    case '3':
                        nextRow[j * 4 + 1] = true;
                        nextRow[j * 4] = true;
                        break;
                    case '4':
                        nextRow[j * 4 + 2] = true;
                        break;
                    case '5':
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4] = true;
                        break;
                    case '6':
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4 + 1] = true;
                        break;
                    case '7':
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4 + 1] = true;
                        nextRow[j * 4] = true;
                        break;
                    case '8':
                        nextRow[j * 4 + 3] = true;
                        break;
                    case '9':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4] = true;
                        break;
                    case 'A':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 1] = true;
                        break;
                    case 'B':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 1] = true;
                        nextRow[j * 4] = true;
                        break;
                    case 'C':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 2] = true;
                        break;
                    case 'D':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4] = true;
                        break;
                    case 'E':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4 + 1] = true;
                        break;
                    case 'F':
                        nextRow[j * 4 + 3] = true;
                        nextRow[j * 4 + 2] = true;
                        nextRow[j * 4 + 1] = true;
                        nextRow[j * 4] = true;
                        break;
                }
            }
            if (i != 0 && i % x == 0) {
                //check that all the rows/cols match up
                x = checkValidRows(lastNums, x);
                lastNums.clear();
            }
            lastNums.add(new ArrayList<>());

            if (i == 0) {
                for (int j = 0; j < n; j++) {
                    if (nextRow[j] != nextRow[0]) {
                        if (n % j == 0) {
                            x = j;
                        } else {
                            x = 1;
                        }
                        break;
                    } else if (j == n - 1) {
                        x = n;
                    }
                }
            }
            for (int j = 0; j < n / x; j++) {
                lastNums.get(i % x).add(nextRow[j * x]);
                for (int k = j * x; k < (j + 1) * x - 1; k++) {
                    if (nextRow[k] != nextRow[k + 1]) {
                        int newX = 1 + k - j * x;
                        if (x % newX == 0) {
                            x = newX;
                            lastNums.get(i % x).clear();
                            j = -1;
                        } else {
                            x = 1;
                        }
                    }
                }
            }
            if (x == 1) {
                System.out.println(x);
                return;
            }
        }
        x = checkValidRows(lastNums, x);
        System.out.println(x);
        br.close();
    }

    private static int checkValidRows(List<List<Boolean>> lastNums, int x) {
        for (int j = 0; j < lastNums.get(0).size(); j++) {
            for (int k = 1; k < lastNums.size(); k++) {
                int diff = lastNums.get(k).size() / lastNums.get(0).size();
                for (int l = 0; l < diff; l++) {
                    if (lastNums.get(0).get(j) != lastNums.get(k).get(l + j * diff)) {
                        if (x % (l + 1) == 0) {
                            x = l + 1;
                        } else {
                            x = 1;
                        }
                    }
                }
            }
        }
        return x;
    }
}
