#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#include<queue>
int n,m,i,o,p,ans;
vector<int> a[200010],b;
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d %d",&o,&p),a[o].pb(p);
	int t=0;
	for (i=0;i<=m;i++)
		for (int j=0;j<a[i].size();j++)
			if (t<i) t++,q.push(a[i][j]);else q.push(a[i][j]),b.pb(q.top()),q.pop();
	sort(b.begin(),b.end(),greater<int>());
	int s=m+1;ans=b.size();
	for (i=0;i<b.size();i++)
		if (s==t+1) break;else if (b[i]<s) s--,ans--;
	printf("%d\n",ans);
}