P29611 [洛谷] Adaptive PVZ
普及+
题目描述

Problem Background

After brutally solving today's toxic 3D computational geometry problem, $\color{black}\texttt{Q}\color{red}\texttt{wQcOrZ}$ opened an interesting .exe file.

Problem Description

Poor $\color{black}\texttt Q\color{red}\texttt{wQcOrZ}$ encounters $n$ zombies on the lawn. The $i$-th zombie appears at time $l_i$ and will enter the house at time $r_i$.

$\color{black}\texttt Q\color{red}\texttt{wQcOrZ}$ has $m$ peashooters. If a peashooter continuously attacks the $i$-th zombie from time $l_i$ to $r_i$ (excluding the endpoints), it can kill the $i$-th zombie. However, during the attack, it cannot attack any other zombies, and the target zombie cannot be changed.

Now, $\color{black}\texttt Q\color{red}\texttt{wQcOrZ}$ wants to know the minimum number of zombies that will enter his house under a reasonable arrangement.

Input Format

The first line contains two integers $n$ and $m$, representing the number of zombies and the number of peashooters, respectively.

The next $n$ lines each contain two integers $l_i$ and $r_i$, representing the appearance time and the entering house time of the $i$-th zombie, respectively.

Output Format

An integer representing the answer.

Sample Input and Output

Sample Input #1

2 1
1 2
3 4

Sample Output #1

0

Sample Input #2

3 2
1 3
1 3
2 4

Sample Output #2

1

Sample Input #3

2 1
1 3
3 5

Sample Output #3

0

Notes

For $30\%$ of the data, $n, m \leq 6$.
For $60\%$ of the data, $n, m \leq 10^3$.
For another $20\%$ of the data, $m \geq n$.
For $100\%$ of the data, $1 \leq n, m \leq 2 \times 10^5$, $1 \leq l_i < r_i \leq 10^9$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 1 1 2 3 4
样例输出
0