Sorting a permutation

Consider a permutation of the numbers of 1 to nn, for a certain given nn. At every step, you can choose one ii between 1 and nn, and to turn the elements of the first ii positions of the permutation. The aim is to leave the permutation sorted (in increasing or decreasing order).

Write a program that computes the minimal number of necessary steps to sort a given permutation.

Input

Input consists of a natural n>0n > 0, followed by a permutation of the numbers from 1 to nn.

Output

Your program must print the minimal number of necesary steps to sort the permutation, following the format of the instances.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:14:52.585Z

© Jutge.org, 2006–2026.
https://jutge.org