eolymp
bolt
Try our new interface for solving problems
Problems

Sort Machine

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. \InputFile The first line contains the size of the list \textbf{N} (\textbf{N} ≤ \textbf{50}). The next line contains \textbf{N} distinct integers - the elements of the list. All numbers in a list are integers between \textbf{-1000} and \textbf{1000} \OutputFile 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