Given two permutations p = (p_1, p_2, \ldots, p_N) and q = (q_1, q_2, \ldots, q_N) of the numbers from to , find the smallest non-negative integer such that p^d = q. That is, applying the permutation times to the array (1, 2, \ldots, N) results in the array .
The first line contains the integer (1 \leq N \leq 2 \times 10^5). The next two lines contain the permutations and , respectively. Each line contains integers representing the corresponding permutation.
Print the smallest non-negative integer such that p^d = q. If no such exists, print .
Esempio 1