#include <bits/stdc++.h>
int N, M, ans, cnt, tot;
struct Data{ int L, R; } a[200010], *sta[200010];
bool cmp(const Data &i, const Data &j){ return i.L > j.L; }
struct cmp1{ bool operator () (const int &i, const int &j){ return a[i].R < a[j].R; } };
std::priority_queue<int, std::vector<int>, cmp1> Q;
int main()
{
	scanf("%d %d", &N, &M);
	for(int i = 1; i <= N; ++i) scanf("%d %d", &a[i].L, &a[i].R);
	std::sort(a + 1, a + N + 1, cmp);
	int p = 1;
	for(int i = a[1].L; i; --i)
	{
		while(p <= N && a[p].L == i) Q.push(p++);
		if(!Q.empty()) Q.pop();
	}
	while(p <= N && a[p].L == 0) Q.push(p++);
	for(int i = M, lim = N - Q.size(); i > lim; --i)
	{
		while(!Q.empty() && a[Q.top()].R > i){ ++ans; Q.pop(); }
		if(Q.empty()) break;
		Q.pop();
	}
	printf("%d\n", ans + Q.size());
	return 0;
}