#include<bits/stdc++.h>
#define N 200005
using namespace std;
vector<int> v[N];
int n,m;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r;i<=n;i++) scanf("%d%d",&l,&r),v[l].push_back(r);
	priority_queue<int,vector<int>,greater<int> > pq,pq2;
	
	int num=0;
	for(int i=0,cnt=0;i<=m;i++){
		if(i!=0) cnt++;
		for(auto x:v[i]){
			pq.push(x);
			if(cnt!=0) num++,cnt--;
			else pq2.push(m+1-pq.top()),pq.pop();
		}
	}
	int ans=0;
	for(int i=0,cnt=0;i<=m-num;i++){
		while(!pq2.empty()&&pq2.top()<i) ans++,pq2.pop();
		if(i!=0&&!pq2.empty()) pq2.pop();
	}
	cout<<ans+pq2.size()<<endl;
	return 0;
}