PivotOJ

Fire

시간 제한: 2000ms메모리 제한: 1024MB출처: BOI 2024BOJ 31971

문제

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 sis_i and eie_i. The number sis_i is her own earliest time in the day when she may start working, and the number eie_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 si>eis_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 sis_i, and end her shift not later than eie_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 sis_i and eie_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

입력
4 100
10 30
30 70
20 40
60 20
출력
3

예제 2

입력
1 100
30 40
출력
-1
코드를 제출하려면 로그인하세요.