#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long LL;
using ld = long double;
using namespace std;
#define MAXN 500005
const double eps = (1e-11);
const int logn = 21;
const double pi = acos(-1.0);
int pp = 1000000007;
#define P pair<int,int>
#define se second
#define fi first
#define MP(i,j) make_pair(i,j)
//#define int LL
const int INF = 1e9;

//假题，贪心模拟^
//正解霍尔定理？下次下次
struct peo {
	int l; int r;
};

peo p[MAXN];

//这里肯定是要从小到大，这样就可以尽量填小的了
bool cmp1(peo a, peo b) {
	if (a.l == b.l) return a.r < b.r;
	return a.l < b.l;
}

bool operator <(peo a, peo b) {
	return a.r > b.r;
}

priority_queue<peo> q;
priority_queue<int> q2;

signed main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &p[i].l, &p[i].r);
	}
	sort(p + 1, p + n + 1, cmp1);
	int left = 0;
	for (int i = 1; i <= n; i++) {
		q.push(p[i]);
		if (q.size() > p[i].l) {
			q2.push(q.top().r);
			q.pop();
		}
	}
	int ans = q.size();
	int r = m + 1;
	int ans2 = 0;
	while (!q2.empty()) {
		int tmp = q2.top(); q2.pop();
		r = min(tmp, r);
		r = max(tmp, ans + 1);
		if (ans2 < m - r + 1) {
			ans2++;
		}
	}
	ans += ans2; ans = n - ans;
	printf("%d", ans);
	return 0;
}