#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const int N = (int)2e5+5;
int n, m, n2, b[N];
ii a[N];
priority_queue<int, vector<int>, greater<int> > pq;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
	sort(a + 1, a + n + 1);
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		pq.push(a[i].second);
		while (SZ(pq) > a[i].first) b[++n2] = pq.top(), pq.pop();
	}
	res += SZ(pq);
	while (SZ(pq)) pq.pop();
	sort(b + 1, b + n2 + 1);
	int lo = res + 1;
	for (int i = n2; i >= 1; --i) {
		pq.push(-b[i]);
		while (SZ(pq) > m - max(b[i], lo) + 1) pq.pop();
	}
	res += SZ(pq);
	printf("%d", n - res);
	return 0;
}
