Under construction

Still being built. Things may change

Training

Interview

Time limit1sMemory limit2048 MB

Summary
Given problems with skill ranges [l, r] in a fixed order, choose which to solve so the final skill level is maximized, where a solve needs the current skill inside the range.
Level

Medium4 of 10

Topics
Greedy, Simulation
Solved
No attempts yet

Problem

Ashley is training for a programming contest on Brandon's Online Judge. The judge has a new feature that lets Ashley's coach, Tom, load a list of problems for her.

Each problem has two integers, a lower skill bound ll and an upper skill bound rr. Each programmer has an integer skill level. If a programmer whose skill level is between ll and rr (inclusive) solves the problem, their skill level goes up by 11.

Ashley trains on Tom's list in the order Tom loaded the problems. For each problem, she either solves it or skips it. Once she skips a problem, she cannot go back to it.

Compute the maximum skill level Ashley can have if she chooses to solve or skip problems optimally.

Input

The first line contains two integers nn and ss (1≤n≤1051 \le n \le 10^5, 0≤s≤1090 \le s \le 10^9), where nn is the number of problems and ss is Ashley's current skill level.

Each of the next nn lines contains two integers ll and rr (0≤l≤r≤2⋅1090 \le l \le r \le 2 \cdot 10^9), the lower and upper skill bounds of a problem, in the order Tom loaded them.

Output

Output a single integer, the maximum skill level Ashley can attain.

Examples1

  1. Example 1

    Input
    3 0
    0 2
    0 0
    1 1
    
    Expected output
    2