#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int m;
inline int read(){
	int u=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){u=u*10+c-'0';c=getchar();}
	return u*f;
}

struct node{
	int l,r,bo;
}p[maxn];
int ans,n;
bool cmpl(node x,node y){
	return (x.l==y.l?x.r>y.r:x.l<y.l);
}
bool cmpr(node x,node y){
	return x.r>y.r;
}
int l=0,r=0;
int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++)p[i].l=read(),p[i].r=read();
	sort(p+1,p+n+1,cmpl);l=1;r=m;
	for(int i=1;i<=n;i++){
		if(l>m)break;
		if(l<=p[i].l){
			l++;
			p[i].bo=1;
			ans++;
		}
	}
	sort(p+1,p+n+1,cmpr);
	for(int i=1;i<=n;i++){
		if(r<l)break;
		if(r>=p[i].r&&!p[i].bo){
			ans++;r--;
			p[i].bo=1;
		}
	}
	cout<<n-ans<<endl;
	return 0;
}