favorite We need a little bit of your help to keep things running, click on this banner to learn more
Problems

# Sort Machine

We have a sorting machine that works on a list of distinct numbers. This machine only has one instruction named MOVE that takes one element of the list as a parameter. The MOVE instruction removes the element from the list and then appends it to the end of the remaining list.

For example, the sequence 19, 7, 8, 25 can be sorted in ascending order using 2 instructions:

MOVE 19, to get 7, 8, 25, 19

MOVE 25, to get 7, 8, 19, 25

You will be given a list of distinct numbers. Return the minimum number of instructions required to sort the list in ascending order.

Input

The first line contains the size of the list N (N50). The next line contains N distinct integers - the elements of the list. All numbers in a list are integers between -1000 and 1000

Output

Print the minimum number of instructions required to sort the list in ascending order.

Time limit 1 second
Memory limit 64 MiB
Input example #1
3
1000 -1000 0
Output example #1
1