#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
	char ch=GC;T w=1,x=0;
	while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
	n=x*w;
}
const int maxn=200005;
#define pii pair<int,int>
#define fir first
#define sec second
int n,m,top,st[maxn];
pii a[maxn];
bool cmp(pii x,pii y){
	return x.fir!=y.fir?x.fir<y.fir:x.sec>y.sec;
}
priority_queue <int,vector<int>,greater<int> > Q;
int main(){
	read(n),read(m);
	for(int i=1;i<=n;i++) read(a[i].fir),read(a[i].sec);
	sort(a+1,a+n+1,cmp);
	int L=1,R=m;
	for(int i=1;i<=n;i++){
		Q.push(a[i].sec);
		if(L<=R&&L<=a[i].fir) L++;
		else{
			st[++top]=Q.top();
			Q.pop();
		}
	}
	sort(st+1,st+top+1);
	int ans=0;
	for(int i=top;i>=1;i--){
		if(L<=R&&R>=st[i]) R--;
		else ans++;
	}
	cout<<ans<<endl;
	return 0;
}