#include<bits/stdc++.h>
const int N=2e5+7;
int n,m,p=0,rs[N],rp=0;
std::priority_queue<int,std::vector<int>,std::greater<int> >q;
struct itv{
	int l,r;
	bool operator<(const itv&w)const{return l<w.l;}
	void cal(){
		q.push(r);
		if(q.size()>l)rs[rp++]=q.top(),q.pop();
	}
}is[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)scanf("%d%d",&is[i].l,&is[i].r);
	std::sort(is,is+n);
	for(int i=0;i<n;++i)is[i].cal();
	std::sort(rs,rs+rp);
	int ans=q.size(),p=ans+1;
	for(int i=0;i<rp;++i){
		int x=rs[i];
		if(p<x)p=x;
		if(p>m)break;
		++ans,++p;
	}
	printf("%d\n",n-ans);
	return 0;
}