#abc233f. [abc233_f]Swap and Sort

[abc233_f]Swap and Sort

Problem Statement

We have a permutation P=(P1,P2,ldots,PN)P=(P_1,P_2,\\ldots,P_N) of (1,2,ldots,N)(1,2,\\ldots,N).

There are MM kinds of operations available to you. Operation ii swaps the aia_i-th and bib_i-th elements of PP.

Is it possible to sort PP in ascending order by doing at most 5times1055\\times 10^5 operations in total in any order?

If it is possible, give one such sequence of operations. Otherwise, report so.

Constraints

  • 2leqNleq10002\\leq N \\leq 1000
  • PP is a permutation of (1,2,ldots,N)(1,2,\\ldots,N).
  • $1\\leq M \\leq \\min(2\\times 10^5, \\frac{N(N-1)}{2})$
  • 1leqailtbileqN1\\leq a_i \\lt b_i\\leq N
  • (ai,bi)neq(aj,bj)(a_i,b_i)\\neq (a_j,b_j) if ineqji\\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN P1P_1 P2P_2 ldots\\ldots PNP_N MM a1a_1 b1b_1 a2a_2 b2b_2 vdots\\vdots aMa_M bMb_M

Output

If it is possible to sort PP in ascending order, print the following:

KK c1c_1 c2c_2 ldots\\ldots cKc_K

Here, KK represents the number of operations to do, and cic_i (1leqileqK)(1\\leq i \\leq K) means the ii-th operation to do is Operation cic_i.
Note that 0leqKleq5times1050\\leq K \\leq 5\\times 10^5 must hold.

If it is impossible to sort PP in ascending order, print -1.


Sample Input 1

6
5 3 2 4 6 1
4
1 5
5 6
1 2
2 3

Sample Output 1

3
4 2 1

PP changes as follows: $(5,3,2,4,6,1)\\to (5,2,3,4,6,1)\\to (5,2,3,4,1,6)\\to (1,2,3,4,5,6)$.


Sample Input 2

5
3 4 1 2 5
2
1 3
2 5

Sample Output 2

-1

We cannot sort PP in ascending order.


Sample Input 3

4
1 2 3 4
6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 3

0

PP may already be sorted in ascending order.

Additionally, here is another accepted output:

4
5 5 5 5

Note that it is not required to minimize the number of operations.