#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,l,r,tot,ans,tmp[200010];
pair<int,int>a[200010];
priority_queue<int>q;
char buffer[10000010],*hed;
char Getchar(){
	return *hed++;
}
int rd(){
	int x=0;
	char c;
	do c=Getchar();
	while(!isdigit(c));
	do{
		x=(x<<1)+(x<<3)+(c^48);
		c=Getchar();
	}while(isdigit(c));
	return x;
}
int main(){
	fread(buffer,1,10000000,stdin);
	hed=buffer;
	n=rd(),m=rd();
	l=1,r=m;
	for(int i=1;i<=n;i++)
		a[i].first=rd(),a[i].second=-rd();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		q.push(a[i].second);
		if(l<=r&&l<=a[i].first)
			l++;
		else{
			tmp[++tot]=-q.top();
			q.pop();
		}
	}
	sort(tmp+1,tmp+tot+1);
	for(int i=tot;i>=1;i--){
		if(l<=r&&tmp[i]<=r)
			r--;
		else ans++;
	}
	printf("%d",ans);
	return 0;
}