Fire

시간 제한2초메모리 제한1024 MB

요약
각 지원자는 하루 중 정해진 구간에서만 일할 수 있으며, 매일 반복되는 근무로 하루 전체를 빈틈없이 덮는 최소 인원을 구한다. 불가능하면 -1을 출력한다.},
난이도

보통10점 중 6점

유형
구간, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

In the old Baltic religion, it is important to have a holy fire burning. A priest called krivis is responsible for protecting it from extinguishing. He has many trustworthy helpers called vaidilutės, and wants to create a schedule for them to stoke and protect the fire. He has to ensure that the fire is always maintained by some vaidilutė.

Krivis has his own time measurement system, where each day has MM minutes. There are NN vaidilutės in his village. The ii-th vaidilutė's possible work time are described by two integers s_is\_i and e_ie\_i. The number s_is\_i is her own earliest time in the day when she may start working, and the number e_ie\_i is the latest time of the day when she needs to finish working. Time is counted in minutes from the start of the day. Note that when s_i>e_is\_i > e\_i, the vaidilutė is willing to work overnight.

Krivis asked you to choose some vaidilutės and arrange shifts for them. A chosen vaidilutė must start her shift not earlier than time s_is\_i, and end her shift not later than e_ie\_i. A single shift is always shorter than the whole day. The chosen vaidilutės will repeat their shifts everyday.

Handing things over from one vaidilutė to the next increases the risk of the fire extinguishing. Because of this, you want to minimize the number of times this happens during the day and will arrange a schedule where the smallest possible number of vaidilutės is needed.

Calculate the minimum number of vaidilutės that you need to choose, such that the holy fire is maintained at all times.

입력

The first line contains two integers NN and MM – the number of vaidilutės available and the length of the day in minutes.

Then NN lines follow. The ii-th of them contains two integers s_is\_i and e_ie\_i – the earliest starting time and the latest finishing time of the ii-th vaidilutė.

출력

Output one integer – the minimum number of vaidilutės you need to choose. If it is impossible to choose the vaidilutės according to the requirements, output −1-1.

제한

  • 1≤N≤2⋅1051 ≤ N ≤ 2 \cdot 10^5
  • 2≤M≤1092 ≤ M ≤ 10^9
  • 0≤s_i,e_i<M0 ≤ s\_i , e\_i < M (for all 1≤i≤N1 ≤ i ≤ N)
  • s_i≠e_is\_i \ne e\_i (for all 1≤i≤N1 ≤ i ≤ N)

예제2

  1. 예제 1

    입력
    4 100
    10 30
    30 70
    20 40
    60 20
    
    예상 출력
    3
    
  2. 예제 2

    입력
    1 100
    30 40
    
    예상 출력
    -1