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
Kaarlo knows that he is light enough to safely step on ice that is at least
Constraints
Input Specification
The first line contains two integers
The next
Output Specification
Output an integer representing the inches of ice Kaarlo must move. If it is impossible, output -1
.
Sample Input
5 3
4
2
7
2
1
Sample Output
4
Comments