Page not loading? Try clicking here.
Placeholder

#5195
Subtask

In place 1s 32MB

Problems

N cards are placed in a row from left to right. 

Each card has an integer written on it, and the integer written on the i-th card from the left is A_i (1 <= i <= N).

 

You can choose and remove some of the N cards. At this time, the order of the remaining cards is preserved.

 

For example, let N = 5 and A = [3, 1, 4, 1, 5]. 

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 x-th card from the left among the remaining cards is exactly x, let's call that card a fixed-position card. 

If all remaining cards are fixed-position cards, let's say it has reached a fixed-position state.

 

For example, let N = 8 and A = [6, 1, 2, 3, 2, 4, 5, 10]. 

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 N = 6 and A = [3, 4, 6, 10, 2, 5], to reach a fixed-position state, all cards must be removed so that no cards remain.

 

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 N (1 ≤N ≤250,000).

The second line contains N integers A_1, ... A_N (1 < A_i​ ≤250,000) in order.


Output

Print the answer on the first line.


Subtask

# Score Condition
#15

N = 1

#216

N < 20

#328

N ≤1,500

#451

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


Source

KOI 2차 2022 초1

You must sign in to write code.