#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y;
}a[200010];
priority_queue<int>q;
int n,m,ans,cnt,b[200010];
bool cmpx(aaa a,aaa b){
	return a.x<b.x;
}
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int i,l,r;
	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++)scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+m+1,cmpx);
	l=1;r=n;
	for(i=1;i<=m;i++){
		q.push(-a[i].y);
		if(l<=r&&l<=a[i].x)l++;
		 else{
		 	b[++cnt]=-q.top();q.pop();
		 }
	}
	sort(b+1,b+cnt+1,cmp);
	for(i=1;i<=cnt;i++){
		if(l<=r&&r>=b[i])r--;
		 else ans++;
	}
	printf("%d",ans);
}