#include<bits/stdc++.h>
using namespace std;

const int maxn=2e5+10;

int n,m,R[maxn];
struct Point{
	int x,y;
	bool operator < (const Point &p) const {return x<p.x;}
}P[maxn];
priority_queue<int,vector<int>,greater<int> > q;

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		scanf("%d%d",&P[i].x,&P[i].y);
	sort(P+1,P+n+1);

	int cL=0,cR=0;
	for (i=1;i<=n;i++)
	{
		if (cL<P[i].x)
		{
			q.push(P[i].y);
			cL++;
		}
		else
		{
			q.push(P[i].y);
			R[++R[0]]=q.top();
			q.pop();
		}
	}
	for (i=1;i<=R[0];i++)
	{
		R[i]=max(R[i],cL+1);
		R[i]=m-R[i]+1;
	}
	sort(R+1,R+R[0]+1);
	for (i=1;i<=R[0];i++)
		if (cR<R[i]) cR++;
	printf("%d\n",n-cL-cR);
}
