#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
priority_queue <pi,vector<pi>,greater<pi>> q;
int n,m,l,r,ans;
struct note{
	int l,r,use;
}a[200005];
bool cmp(note x,note y) { return x.l<y.l; }
bool cmp1(note x,note y) { return x.r>y.r; }
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	std::sort(a+1,a+n+1,cmp);
	l=1,r=m;
	for (int i=1;i<=n;i++){
		if (a[i].l==0) continue;
		if (a[i].l>=l){
			l++,ans++,q.push(make_pair(a[i].r,i));
			a[i].use=1;
		}else{
			pi t=q.top();
			if (a[i].r>t.first){
				q.pop();
				a[i].use=1;
				a[t.second].use=0;
				q.push(make_pair(a[i].r,i));
			}
		}
	}
	std::sort(a+1,a+n+1,cmp1);
	for (int i=1;i<=n;i++){
		if (a[i].use || a[i].r>m) continue;
		if (r<l) break;
		if (a[i].r<=r) r--,ans++;
	}
	printf("%d\n",n-ans);
} 