Denesh is walking along a pathway in a forest. He encounters a part of the trail where there is a patch of wet mud that is
Denesh can jump as far as -1
.
Note: It takes no time for Denesh to complete a jump.
Input Specification
The first line will contain three integers,
The next
Constraints
Subtask 1 [20%]
Subtask 2 [80%]
Output Specification
Output the minimum number of minutes it will take Denesh to get to the other side of the trail, or -1
if it is impossible.
Sample Input 1
4 2 3
4 1
3 4
Sample Output 1
4
Explanation for Sample Output 1
After 4 minutes, Denesh can get across the wet mud in 2 jumps. First by jumping to the dry mud at the third inch, and then jumping to the other side of the trail.
Sample Input 2
4 4 1
3 2
4 5
1 1
2 3
Sample Output 2
5
Explanation for Sample Output 2
After the first minute, Denesh can jump to the first inch of mud. He then has to wait 3 minutes to jump to the second patch of mud, and then immediately after jumps to the third patch of mud. After the fifth minute, he takes two jumps to the other side of the trail.
Sample Input 3
3 1 1
1 2
Sample Output 3
-1
Comments
How can Denesh jump 0 inches?