Training

시간 제한1초메모리 제한2048 MB

요약
고정된 순서로 주어진 n개의 문제 각각에 대해, 현재 실력이 [l, r] 범위에 들어갈 때 풀면 실력이 1 오른다. 풀 문제를 골라 최종 실력을 최대로 만든다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법, 정렬, 이분 탐색
정답자
아직 제출이 없습니다

문제

Ashley is training for a programming contest on Brandon's Online Judge. Brandon's Online Judge has a new feature which allows Ashley's coach, Tom, to load a list of problems for Ashley.

Tom has curated some problems for Ashley to work on. Each problem has two integers as a lower skill bound and an upper skill bound. Each programmer has an integer skill level. If someone with a skill level between the lower and upper bounds of a problem (inclusive), and they solve that problem, then his/her skill level goes up by 11.

Ashley will train on Tom's curated list of problems as follows -- she will look at the first problem on the list and either solve it or skip it. She will repeat this for every problem on the list in the order Tom loaded the problems. Once she has skipped a problem, she can never go back to it.

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

입력

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

Each of the next nn lines contains two integers ll and rr (0≤l≤r≤2⋅109)(0 \le l \le r \le 2 \cdot 10^9). These are the lower (ll) and upper (rr) skill bounds on each of Tom's problems, in the order that Tom loaded them.

출력

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

예제1

  1. 예제 1

    입력
    3 0
    0 2
    0 0
    1 1
    
    예상 출력
    2