Locked Away
You are trying to break into AllUni Co. to steal the reference solutions to the contest problems, but Patrick and Patrick were one step ahead of you, implementing tough security by chaining locks together to secure the outside gates. Specifically, there is a chain of locks with locks on it connected in a single line. Each lock is numbered
to
, with the lock labelled
being the leftmost lock.
However, luckily, you thought ahead and brought bolt cutters with you. Over time you will cut different locks off the chain to see what happens. You are interested in how many different contiguous segments of locks remain after all removals, so you can find a way to totally unlock the gate.
How many segments of connected locks will there be after all removals?
Input
The first line consists of two integers and
— the number of locks, and the number of removals.
The next line consists of integers
. Each integer in this line will be unique.
represents the number of the lock that will be removed at the
th time, labelled
to
.
Output
Output a single integer — the total amount of lock segments remaining after all removals.
Example
Input 1
9 4
1 5 7 2
Output 1
3
Initially, we start with all locks.
123456789
In each subsequent step of removing a lock, we will be left with the following segments:
23456789 - removed lock 1
234 6789 - removed lock 5
234 6 89 - removed lock 7
34 6 89 - removed lock 2
In the end, we are left with 3 distinct segments of locks, 34, 6, and 89.
Comments
sugma
light work no reaction
sw
you saw nothing
dsfsakdslaf