#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#include<queue>
#define N 1001000
int n,m,i,o,p,ans;
vector<int> a[N],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();
			}
		}
	}
	//pr(t);
	sort(b.begin(),b.end(),greater<int>());
//	pri(b,b.size()-1);
	int s=m+1;
	ans=b.size();
	for (i=0;i<b.size();i++)
	{
		if (s==t+1) break;
		if (b[i]<s) s--,ans--;
	}
	printf("%d\n",ans);
}
	