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 (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>

#define N	200000
#define M	200000
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(M))) */

int max(int a, int b) { return a > b ? a : b; }

int ll[N], rr[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return ll[i] - ll[j];
}

int sum[N_ * 2], suf[N_ * 2], n_;

void pul(int i) {
	int l = i << 1, r = i << 1 | 1;

	sum[i] = sum[l] + sum[r];
	suf[i] = max(suf[r], suf[l] + sum[r]);
}

void build(int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 1; i < n - 1; i++)
		sum[n_ + i] = -1;
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i) {
	i += n_;
	suf[i] = max(sum[i]++, 0);
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	static int ii[N];
	int n, m, i, l, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &ll[i], &rr[i]);
		ii[i] = i;
	}
	qsort(ii, n, sizeof *ii, compare);
	build(m + 2);
	ans = 0;
	for (l = 0, i = 0; l <= m; l++) {
		while (i < n && ll[ii[i]] == l)
			update(rr[ii[i++]]);
		ans = max(ans, suf[1] - l);
	}
	printf("%d\n", ans);
	return 0;
}