CSES - Planets Queries II
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are playing a game consisting of n planets. Each planet has a teleporter to another planet (or the planet itself).

You have to process qq queries of the form: You are now on planet aa and want to reach planet bb. What is the minimum number of teleportations?

Input

The first input line contains two integers nn and qq: the number of planets and queries. The planets are numbered 1,2,,n1,2,\ldots,n.

The second line contains nn integers t1,t2,,tnt_1,t_2,\ldots,t_n: for each planet, the destination of the teleporter.

Finally, there are qq lines describing the queries. Each line has two integers aa and bb: you are now on planet aa and want to reach planet bb.

Output

For each query, print the minimum number of teleportations. If it is not possible to reach the destination, print 1-1.

Constraints

  • 1n,q21051 \le n, q \le 2 \cdot 10^5
  • 1a,bn1 \le a,b \le n

Example

Input:

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

Output:

1
2
-1