Find the degree of a permutation .
A permutation of elements is an ordered set of distinct numbers from to .
The degree of a permutation is a minimal positive integer such that , where is an identity permutation .
The first line contains the order of a permutation . The second line contains the permutation itself.
Print the degree of the given permutation.