Consider a Permutation P of length N.
Let us define an operation on P as follows:
For example
Let initially P=[2 3 1]
So, P[1]=2,P[2]=3,P[3]=1
After 1 operation:
P[1] becomes P[P[1]]=P[2]=3
P[2] becomes P[P[2]]=P[3]=1
P[3] becomes P[P[3]]=P[1]=2
So, P becomes [3 1 2]
You need to find the minimum number of operations after which P becomes an Identity Permutation.
Output −1 if not possible.
Note
Input Format
Output Format
Constraints
In Sample 1, the permutation becomes Identity permutation in 1 operation.
In Sample 2, the permutation can never become an Identity permutation, hence answer is −1.