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

        int N = Integer.parseInt(f.readLine());
        String[] board = new String[N];
        String[] res = new String[N];
        
        for (int i=0; i<N; i++)
        	board[i] = f.readLine();
        for (int i=0; i<N; i++)
        	res[i] = f.readLine();

        for (int i=1; i<=3; i++) {
        	if (areSame(res, rotN(board, i))) {
        		out.write(i + "\n");
                f.close();
                out.close();
                System.exit(0);
        	}
        }
        
        if (areSame(res, reflect(board))) {
        	out.write("4\n");
            f.close();
            out.close();
            System.exit(0);
        }
        
        for (int i=1; i<=3; i++) {
        	if (areSame(res, rotN(reflect(board), i))) {
        		out.write("5\n");
                f.close();
                out.close();
                System.exit(0);
        	}
        }
        
        if (areSame(res, board)) {
        	out.write("6\n");
            f.close();
            out.close();
            System.exit(0);
        }
        
        out.write("7\n");
        f.close();
        out.close();
        System.exit(0);
    }