문제
It's winter on the farm, and that means snow! There are
Farmer John starts off on tile
In his foul-weather backpack, Farmer John has
Unfortunately, the boots are packed in such a way that Farmer John can only access the topmost pair at any given time. So at any time, Farmer John can either put on the topmost pair of boots (discarding his old pair) or discard the topmost pair of boots (making a new pair of boots accessible).
Farmer John can only change boots while standing on a tile. If that tile has
Help Farmer John minimize waste, by determining the minimum number of pairs of boots he needs to discard in order to reach the barn. You may assume that Farmer John is initially not wearing any boots.
Problem credits: Brian Dean and Dhruv Rohatgi
입력
The first line contains two space-separated integers
The second line contains
The next
The boots are described in top-to-bottom order, so pair
출력
The output should consist of a single integer, giving the minimum number of boots Farmer John needs to discard. It's guaranteed that it will be possible for FJ to make it to the barn.
예제
10 4
0 2 8 3 6 7 5 1 4 0
2 3
4 2
3 4
7 1
2