Problems
Each card has an integer written on it, and the integer written on the
You can choose and remove some of the
For example, let
If you remove the second and fifth cards, the numbers written on the remaining cards will be 3, 4, and 1 in order from the left.
That is, the number written on the third card from the left among the remaining cards is 1.
After choosing and removing some cards, if the number written on the
If all remaining cards are fixed-position cards, let's say it has reached a fixed-position state.
For example, let
If you remove the first, fifth, and eighth cards, the numbers written on the remaining cards will be 1, 2, 3, 4, and 5 in order.
In this case, all remaining cards become fixed-position cards, and thus it has reached a fixed-position state.
If
Note that removing all cards always results in a fixed-position state.
Write a program to calculate the minimum number of cards that must be removed to reach a fixed-position state.
Input
The first line contains an integer
The second line contains
Output
Print the answer on the first line.
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 5 | |
| #2 | 16 | |
| #3 | 28 | |
| #4 | 51 | No additional constraints. |
Example #1
1
1
0
Example #2
8
6 1 2 3 2 4 5 10
3
Example #3
6
3 4 6 10 2 5
6