A conveyor loop holds n bins arranged in a line. A right-rotation by one moves every bin one step to the right, wrapping the last bin to the front. Determine the minimum number of right-rotations needed so that the bin values become sorted in non-decreasing order. If no number of rotations can achieve this, report -1.
Input format
Line 1: an integer n.
Line 2: n space-separated integers, the bin values.
Output format
A single integer: the minimum number of right-rotations that yields a non-decreasing arrangement, or -1 if impossible.
Constraints
- 1 ≤ n ≤ 100000
- -1000000000 ≤ each value ≤ 1000000000