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>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define pr pair<int, int>
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
const int INF = 1e9 + 7;
const int N = 211111;
int n, m, tt(1);
pr seg[N];
struct segtr{int lc, rc, mx, tag;} tr[N*8];

void pushdown(int x){
	if (!tr[x].tag) return; tr[x].mx += tr[x].tag;
	if (tr[x].lc) tr[tr[x].lc].tag += tr[x].tag;
	if (tr[x].rc) tr[tr[x].rc].tag += tr[x].tag; tr[x].tag = 0;
}
void update(int x){
	pushdown(x), pushdown(tr[x].lc), pushdown(tr[x].rc);
	tr[x].mx = max(tr[tr[x].lc].mx, tr[tr[x].rc].mx);
}
void build(int x, int l, int r){
	if (l == r) tr[x].mx = -(m - l + 1);
	else{
		int mid = (l + r) >> 1;
		tr[x].lc = ++tt, build(tt, l, mid);
		tr[x].rc = ++tt, build(tt, mid + 1, r);
		update(x);
	}
}
void modify(int x, int l, int r, int nl, int nr, int k){
	pushdown(x);
	if (nl <= l&&r <= nr){tr[x].tag += k; return;}
	int mid = (l + r) >> 1;
	if (nl <= mid) modify(tr[x].lc, l, mid, nl, nr, k);
	if (mid <  nr) modify(tr[x].rc, mid + 1, r, nl, nr, k);
	update(x);
}
int query(int x, int l, int r, int nl, int nr){
	pushdown(x);
	if (nl <= l&&r <= nr) return tr[x].mx;
	int mid = (l + r) >> 1, ans = -INF;
	if (nl <= mid) ans = max(ans, query(tr[x].lc, l, mid, nl, nr));
	if (mid <  nr) ans = max(ans, query(tr[x].rc, mid + 1, r, nl, nr));
	return ans;
}

int main(){
	read(n), read(m);
	rep(i, 1, n) read(seg[i].x), read(seg[i].y);
	sort(seg + 1, seg + n + 1);
	int pos = 1, ans = 0; build(1, 0, m + 1);
	rep(i, 0, m + 1){
		for (; pos <= n&&seg[pos].x <= i; ++pos)
			modify(1, 0, m + 1, i + 1, seg[pos].y, 1);
		ans = max(ans, query(1, 0, m + 1, i + 1, m + 1) - i);
	}
	printf("%d\n", max(ans, n - m));
	return 0;
}