One look at his alarm clock and Max knows he's going to be late—or is he? Luckily for Max, it's a late start today! But he better leave the house soon, else he will still be late...
School starts in minutes, and Max quickly checks Google Maps for bus times. He finds buses listed, with the -th bus scheduled to leave the station in minutes. Each bus also differs in speed and number of stops, thus taking minutes to arrive at WLMAC.
Assuming Max lives right beside the station, and that the time needed to walk from the bus stop to the school once he's arrived is negligible, what is the latest time Max can leave his house and still arrive at school on time? Note that Max will still arrive on time if he gets to school in exactly minutes.
Constraints
Input Specification
The first line will contain two integers, and .
The next lines will each contain two integers, and .
Output Specification
Output one integer, the latest time Max must leave his house to arrive at school on time. Output -1
if it is impossible for Max to arrive at school on time.
Sample Input 1
10 5
3 3
4 6
5 3
5 4
6 5
Sample Output 1
5
Sample Input 2
10 3
3 8
5 6
8 4
Sample Output 2
-1
Comments