public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new File("transform.in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("transform.out")));

        int N = in.nextInt();in.nextLine();
        char[][] before = new char[N][N];
        for (int i = 0; i < N; i++) {
            before[i] = in.nextLine().toCharArray();
        }
        char[][] after = new char[N][N];
        for (int i = 0; i < N; i++) {
            after[i] = in.nextLine().toCharArray();
        }

        // check #1, #2, #3
        char[][] tmp = before.clone();
        for (int i = 1; i <= 3; i++) {
            tmp = rotate90(tmp, N);
            if (equals(tmp, after)) {
                out.println(i);
                exit(in, out);
            }
        }
        // check #4
        tmp = reflect(before, N);
        if (equals(tmp, after)) {
            out.println(4);
            exit(in, out);
        }
        // check #5
        for (int i = 1; i <= 3; i++) {
            tmp = rotate90(tmp, N);
            if (equals(tmp, after)) {
                out.println(5);
                exit(in, out);
            }
        }
        //check #6
        if (equals(before, after)) {
            out.println(6);
            exit(in, out);
        }
        //check #7
        out.println(7);
        exit(in, out);
    }