100 atcoder#ABC203C. [ABC203C] Friends and Travel costs

[ABC203C] Friends and Travel costs

Score : 300300 points

Problem Statement

There are 10100+110^{100}+1 villages, labeled with numbers 00, 11, \ldots, 1010010^{100}. For every integer ii between 00 and 10100110^{100}-1 (inclusive), you can pay 11 yen (the currency) in Village ii to get to Village (i+1)(i + 1). There is no other way to travel between villages.

Taro has KK yen and is in Village 00 now. He will try to get to a village labeled with as large a number as possible. He has NN friends. The ii-th friend, who is in Village AiA_i, will give Taro BiB_i yen when he reaches Village AiA_i. Find the number with which the last village he will reach is labeled.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1K1091 \leq K \leq 10^9
  • 1Ai10181 \leq A_i \leq 10^{18}
  • 1Bi1091 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 B1B_1

::

ANA_N BNB_N

Output

Print the answer.

2 3
2 1
5 10
4

Takahashi will travel as follows:

  • Go from Village 00 to Village 11, for 11 yen. Now he has 22 yen.
  • Go from Village 11 to Village 22, for 11 yen. Now he has 11 yen.
  • Get 11 yen from the 11-st friend in Village 22. Now he has 22 yen.
  • Go from Village 22 to Village 33, for 11 yen. Now he has 11 yen.
  • Go from Village 33 to Village 44, for 11 yen. Now he has 00 yen, and he has no friends in this village, so his journey ends here.

Thus, we should print 44.

5 1000000000
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6000000000

Note that the answer may not fit into a 3232-bit integer.

3 2
5 5
2 1
2 2
10

He may have multiple friends in the same village.