# Problem: Vitamin D

Want to try solving this problem? You can submit your code online if you log in or register.

## Vitamin D

Time Limit: 1 second
Memory Limit: 128 MB
Input File: standard input
Output File: standard output

After spending all night coding solutions to informatics problems, Nicole is keen to get some vitamin D: by relaxing in a nice, sunny spot on the beach.

Unfortunately due to the Earth's rotation and cloud movements, the sun is not so consistent in where it chooses to shine on the beach. Specifically, for each minute i, the sun shines brightly on the section of beach that is between ai and bi metres from the left end of the beach (ai < bi). Everywhere else on the beach during that minute is unbearably cold - so cold that Nicole can not possibly sit there during that minute.

Nicole has already calculated from Bureau of Meterology data where the sunny section of the beach will be for each of the following N minutes (after which she must leave for a hackathon). Your task is to develop an algorithm that will determine the best spot for her to soak up vitamin D and when to sit there.

Nicole wants to sit in the sun for as long as possible without having to move. Therefore, your program must find the longest period of time during which there exists a spot on the beach that is in sunlight for this whole period (that is, there is no minute during this period in which the spot is not sunlit). Note that a "spot" to sit must be at least one metre wide, so for Nicole to sit x metres along the beach, the one-metre section between x and x+1 must be sunny.

### Input

• The first line of input will contain two space-separated integers: N, the number of minutes Nicole has weather data for, and L, the length of the beach.

• The following N lines of input will each contain two space-separated integers ai and bi (0 ≤ ai < bi ≤ L), representing the start and end of the sunny section of beach during minute i.

### Output

Output should consist of one line containing one integer: the maximum number of consecutive minutes during which Nicole can sit in some sunny spot on the beach.

```5 10
6 10
0 6
5 8
1 9
1 5
```

```3
```

### Explanation

Nicole can sit 5 metres from the left end of the beach (between 5m and 6m) from the end of the first minute to the end of the fourth minute. There is no spot that is continuously sunny for longer than 3 minutes.

• For Subtask 1 (20 points), 1 ≤ N ≤ 100,000 and 1 ≤ L ≤ 100.

• For Subtask 2 (20 points), 1 ≤ N ≤ 1,000 and 1 ≤ L ≤ 1,000,000.

• For Subtask 3 (60 points), 1 ≤ N ≤ 100,000 and 1 ≤ L ≤ 1,000,000.

Privacy statement
`Page generated:  3 June 2023,  1:49pm AEST`