Олимпиадный тренинг

Задача 21820. Sequence conversion


Задача

Темы:
The math teacher does not like Kolya very much and always makes him answer the most at the blackboard
challenging tasks.
So today she wrote a sequence of n non-negative integers on the blackboard
numbers a1, a2, . . . , an and called Kolya to the board. In one action, the teacher allows Kolya
Erase any number and write a number one more in its place. The teacher demands from
If for the minimum number of actions to achieve that somewhere in this sequence
met in succession in ascending order of numbers from 1 to h.
Help Kolya understand what is the minimum number of actions he can take to achieve what
for some i, ai = 1, ai+1 = 2, . . . , ai+h−1 = h, or find out it's not possible and
the teacher is again mocking poor Kolya with impunity.

Input data format
The first line of the input file contains two natural numbers: n and h (1 ≤ h ≤ n ≤ 200 000).
The second line contains n numbers ai — the initial values ​​of the elements of the written sequence
(0 ≤ ai ≤ n).
Output format
In a single line of the output file, print the minimum number of actions required for which
Kolya will be able to complete the task, or −1 if it is impossible to complete it.

Examples
Input
4 3
1 1 0 2
Conclusion
3

Input
3 2
1 3 2
Conclusion
-1

In the first example, Kolya needs to increase the third number twice by 1 and once — fourth. Then
the sequence will take the form 1, 1, 2, 3, for i = 2 the desired condition is satisfied.
In the second example, it is impossible to get 1 and 2 in a sequence.