Problem:
Score : 1000 points

Problem Statement

There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i.

N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i-th person wishes to sit in a chair whose coordinate is not greater than L_i, or not less than R_i. Naturally, only one person can sit in the same chair.

It may not be possible for all of them to sit in their favorite chairs, if nothing is done.
Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.

Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.

Constraints

1 ≤ N,M ≤ 2 × 10^5

0 ≤ L_i < R_i ≤ M + 1(1 ≤ i ≤ N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
:
L_N R_N

Output

Print the minimum required number of additional chairs.

Sample Input 1

4 4
0 3
2 3
1 3
3 4

Sample Output 1

0

The four people can sit in chairs at the coordinates 3, 2, 1 and 4, respectively, and no more chair is needed.

Sample Input 2

7 6
0 7
1 5
3 6
2 7
1 6
2 6
3 7

Sample Output 2

2

If we place additional chairs at the coordinates 0 and 2.5, the seven people can sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.

Sample Input 3

3 1
1 2
1 2
1 2

Sample Output 3

2

Sample Input 4

6 6
1 6
1 6
1 5
1 5
2 6
2 6

Sample Output 4

2

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
 
#define mp make_pair
#define fi first
#define se second
 
//mt19937 rng(time(NULL)); //int
//mt19937_64 rng(time(NULL)); //Long Long
//shuffle(a.begin(),a.end(),rng); //shuffle
//rng(); //random
 
vector<int>adj[200050];
 
priority_queue<int, vector<int>, greater<int> > jaw;
vector<int> sim;
long long getv(int a, int m) {
	while (!jaw.empty()) jaw.pop();
	sim.clear();
	for (int i = 1; i <= m; i++) {
		for (auto it : adj[i]) jaw.push(it);
		if (i >= m - a + 1) {
			if (jaw.empty()) return -1e18;
			jaw.pop();
		}
	}
	for (auto it : adj[m + 1]) jaw.push(it);
	while (!jaw.empty()) {
		sim.push_back(jaw.top());
		jaw.pop();
	}
 
	int st = 1, en = min((int)sim.size(), m - a), mi, rv = 0;
	while (st <= en) {
		mi = (st + en) / 2;
 		int i;
		for (i = 0; i < mi; i++) if (sim[sim.size() - mi + i] < i + 1) break;
		if (i >= mi) {
			rv = mi;
			st = mi + 1;
		}
		else en = mi - 1;
	}
	return a + rv;
}
int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i= 1; i <= n; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		//t1 = 1, t2 = 2;
		adj[t2].push_back(t1);
	}
 
	int st = 0, en = min(n, m), mi;
	while (st < en) {
		int mi1 = (st + en) / 2;
		int mi2 = mi1 + 1;
 
		long long v1 = getv(mi1, m);
		long long v2 = getv(mi2, m);
		if (v1 >= v2) en = mi2 - 1;
		else st = mi1 + 1;
	}
	long long v = getv(st, m);
	return !printf("%lld\n", n - v);
}