Do you think that sorting is easy? It is not so simple when you're running out of time.
Unexpected things often happen in life. For example, you now have an array and need to sort it in non-decreasing order. The problem is, you really don't have time to do it yourself.
Fortunately, your friend is very skilled at sorting arrays, so you decide to ask for his help. You believe your friend's special skill comes from his conceptual approach: in one second, he can remove any element from the array and place it either at the beginning or the end.
For example, if the array is 4\ 2\ 5\ 6\ 1\ 3, taking out and putting it at the beginning yields 5\ 4\ 2\ 6\ 1\ 3. Taking out and putting it at the end yields 4\ 5\ 6\ 1\ 3\ 2.
Of course, your friend performs all operations as quickly as possible, since he doesn't want to waste time. All you want to know is: how much time will it take your friend to sort your array?
The first line contains (1 \leq n \leq 3 \cdot 10^5): the number of elements in . The second line contains integers A_i (1 \leq A_i \leq 10^6).
Print the minimum time required (in seconds) for your friend to sort .
Example 1