Under construction

Still being built. Things may change

Contests

Time limit1.5sMemory limit1024 MB

Summary
Given N contests as day intervals, find the fewest non-overlapping contests Hyeongseop can still win after K-1 rivals each pick a non-overlapping set of contests.
Level

Hard8 of 10

Topics
Intervals, Greedy, Sorting
Solved
No attempts yet

Problem

Hyeongseop is the KK-th best programmer in the world, but he wants to win as many programming contests as possible so that his name becomes known. When Hyeongseop enters a contest, he always loses to anyone better than him and always beats anyone worse than him. So Hyeongseop can win a contest only when nobody better than him takes part in it, and in such a contest he always wins.

Across the world, NN programming contests are held, and contest ii runs from day SiS_i to day EiE_i. Contests held at different venues, so no one can enter two contests whose periods overlap. Hyeongseop knows in advance which contests the K−1K-1 people better than him will enter. He picks the contests that none of those K−1K-1 people enter, and he enters as many of them as he can so that he wins as many as possible.

If the K−1K-1 people enter contests well, Hyeongseop has few contests left to win. He wants to know the largest number of contests he can win in that case. Write a program that finds the number of contests Hyeongseop can win when the information about the contests is given.

Input

The first line contains the number of contests NN (1≤N≤100,0001 \le N \le 100{,}000) and Hyeongseop's rank KK (1≤K≤100,0001 \le K \le 100{,}000).

Each of the next NN lines contains the start day SiS_i and the end day EiE_i of a contest (1≤Si,Ei≤1,000,000,0001 \le S_i, E_i \le 1{,}000{,}000{,}000).

Output

Print the number of contests Hyeongseop can win when the K−1K-1 people enter contests in a way that makes this number as small as possible.

Examples1

  1. Example 1

    Input
    7 2
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    
    Expected output
    2