Homie from Suomi

View as PDF

Submit solution

Points: 5
Time limit: 1.5s
Memory limit: 64M

Author:
Problem type

In the spirit of Finland Day, Kaarlo is visiting his friend in Oulu. As a proud Finn, Kaarlo is using Finland's national vehicle: skis. A common saying in Finland is to "test the ice with a stick before stepping on it", and Kaarlo is well aware of this rule.

Kaarlo departs from Helsinki and heads straight for Oulu. Along this distance, he gets several of his Finnish friends to test out the ice at every area with sticks. Using advanced Finnish technology, each friend reports an estimated thickness of the ice.

Kaarlo knows that it is dangerous to travel on thin ice, but he wants to go in a straight line to Oulu. He devises a plan: he uses his trusty chisel and shovel to collect ice from the thicker areas and moves them to the thinner areas. This, of course, means that he can only move ice from previously visited areas. When he is moving ice from the area ai, he is considered to be still stepping on that area ai. When he is moving ice to an area ai, he is considered to be stepping on the area ai1 which is right before it. Kaarlo starts at the 1st area and must get to the Nth area. He must traverse across the areas one area at a time in order to get to Oulu. Kaarlo wants to make it to his friend in time for Finland Day, so he wants to move the minimum amount of ice necessary.

Kaarlo knows that he is light enough to safely step on ice that is at least M inches thick. At no point should he be stepping on an area with a thickness ai in which ai<M. Given the thickness reports of N areas along the way, determine the minimum amount of ice Kaarlo must move to make it to his friend safely.

Constraints

1N106

1M1000

1ai1000 for all 1iN

Input Specification

The first line contains two integers N and M, the number of areas and minimum thickness respectively, separated by a space.

The next N lines contain an integer ai representing the thickness in inches of the ith area starting from Helsinki.

Output Specification

Output an integer representing the inches of ice Kaarlo must move. If it is impossible, output -1.

Sample Input

Copy
5 3
4
2
7
2
1

Sample Output

Copy
4

Comments

There are no comments at the moment.