Refrigerators
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
They say that at this time of year, refrigerators of Ukrainian production are in high demand in Alaska. Zenyk and Marichka decided to take advantage of this phenomenon.
There are \(n\) domestically produced refrigerators on the market in Ukraine. Zenyk and Marichka know how many hryvnias they can buy a refrigerator for in Ukraine and how many hryvnias it can be sold for in Alaska. Each of the refrigerators can be purchased in at most one copy.
Our young heroes have \(k\) hryvnias at their disposal. They want to buy some of the refrigerators in their homeland (for this they can spend no more than \(k\) hryvnias) and then sell them in Alaska.
You need to determine the maximum possible amount of money Zenyk and Marichka will have after making the purchase and sale.
Assume that the transportation of refrigerators is free. Note that Zenyk and Marichka can go to sell refrigerators to Alaska only once. Also, they can, if they wish, buy nothing and sell nothing at all.
Input
The first line contains two integers \(n\) and \(k\) — the number of refrigerators on the market and the number of hryvnias the couple initially has.
The next \(n\) lines contain two integers each \(a_i\) and \(b_i\) — the prices of the \(i\)-th refrigerator in Ukraine and in Alaska respectively.
Output
In a single line, output an integer — the maximum possible capital of Zenyk and Marichka after the trip to Alaska.
Constraints
\(1 \le n \le 100\),
\(1 \le k \le 10^4\),
\(1 \le a_i, b_i \le 10^4\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 18 5 8 20 1000 18 25 12 17 7 4 | 26 |
Notes
The optimal choice is to buy the first and fourth refrigerators in Ukraine. Unfortunately, Zenyk and Marichka do not have enough money to buy the second refrigerator, and buying and selling the fifth refrigerator is completely unprofitable.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|