PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000116. Bạn bè và chi phí di chuyển (Friends and Travel costs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bạn bè và chi phí di chuyển (Friends and Travel costs)

Friends and Travel costs

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Taro starts at village 00 with KK coins. Moving from village ii to village i+1i+1 costs exactly one coin. Friend ii lives in village AiA_i and gives him BiB_i coins upon arrival. Multiple friends may share a village. Determine the farthest village he can reach.

Input

The first line contains N,KN,K. Each of the following NN lines contains Ai,BiA_i,B_i.

Output

Print one integer: the farthest reachable village.

Subtasks

  • Subtask 1 (20 points): 1≤N≤251\le N\le 25; 1≤K≤1091\le K\le10^9; 1≤Ai≤10181\le A_i\le10^{18}; 1≤Bi≤1091\le B_i\le10^9 for all ii.
  • Subtask 2 (30 points): 1≤N≤15001\le N\le 1500; 1≤K≤1091\le K\le10^9; 1≤Ai≤10181\le A_i\le10^{18}; 1≤Bi≤1091\le B_i\le10^9 for all ii.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤K≤1091\le K\le10^9; 1≤Ai≤10181\le A_i\le10^{18}; 1≤Bi≤1091\le B_i\le10^9 for all ii.

Examples

Input

2 3
2 1
5 10

Output

4

Explanation

He spends two coins reaching village 22, has one coin remaining, receives one additional coin, and then reaches village 44. He cannot reach village 55, so the answer is 44.