Time limit
2s
Memory limit
128 MB
You are given a permutation of length N containing each integer from 1 through N exactly once.
In one move, choose a starting position and reverse exactly K consecutive numbers from that position to the right. The chosen position must allow all K numbers to stay inside the permutation. For example, if the permutation is 5 4 3 2 1 and K is 3, reversing from the second position changes it to 5 2 3 4 1.
Find the minimum number of moves needed to make the given permutation increasing. If it cannot be done, output -1.
The first line contains N and K. The second line contains the N numbers of the permutation.
Print the minimum number of moves. If the permutation cannot be made increasing, print -1.