#K50407. Taco Hiker

    ID: 28857 Type: Default 1000ms 256MiB

Taco Hiker

Taco Hiker

A hiker wants to traverse a series of checkpoints from the first to the last. Each checkpoint has an elevation given in an array H of size N. The hiker can move to the next checkpoint if its elevation is greater than or equal to the current one. If the immediate next checkpoint does not satisfy this condition, the hiker can jump ahead to the first checkpoint (after the next) with an elevation not lower than the current one.

Your task is to determine the minimum number of moves needed for the hiker to reach the final checkpoint. If it is impossible for the hiker to progress under these rules, output \(-1\).

The movement rule can be expressed in LaTeX as:

$$\text{move} = \begin{cases} 1, & \text{if } H[i+1] \ge H[i] \\ 1, & \text{if there exists } j\ (j > i+1) \text{ such that } H[j] \ge H[i] \\ -1, & \text{if no such } j \text{ exists} \end{cases} $$

inputFormat

The first line contains a single integer N representing the number of checkpoints.

The second line contains N space-separated integers where the i-th integer denotes the elevation at the i-th checkpoint.

outputFormat

Output a single integer representing the minimum number of moves required to reach the final checkpoint from the first checkpoint. If it is impossible to reach the end, output -1.

## sample
5
1 3 2 4 5
3