At just 17 years old, Huseyn feels like an old man and believes it's time for him to leave Computer Science. Therefore, he must complete all his important projects and experiments. He has almost finished all his projects and experiments, with only one remaining. He had a wonderful sorted array, but after numerous experiments, something unforeseen happened: the array was no longer sorted! It might seem simple to sort an array, but Huseyn decided to conduct one more experiment. He wants to sort the array using only two operations:
Take any element of the array and move it to the end of the array.
Take any element of the array and move it to the beginning of the array.
Thus, if the array initially contained elements a_1, a_2, ..., a_{i-1}, a_i, a_{i+1}, ..., a_n and the i-th element was chosen, then if the first operation is applied, the array becomes a_1, a_2, ..., a_{i-1}, a_{i+1}, ..., a_n, a_i. In the case of applying the second operation, it becomes a_i, a_1, a_2, ..., a_{i-1}, a_{i+1}, ..., a_n. It turned out that with these two operations, the array can always be sorted, which Huseyn did with his array. But now Huseyn has given you a new array and asked you to find the minimum number of such operations needed to sort the new array.
The first line contains a single integer – the length of the array given to you by Huseyn (1 \le n \le 300000).
The second line contains integers a_i separated by spaces – the elements of the array (1 \le a_i \le 10^9).
Output a single number – the minimum number of operations needed to apply to the given array to make it sorted.
Example 1
Example 2
Example 3