#include<bits/stdc++.h>
using namespace std;
#define N 1111116

int n,m,ans;
pair<int,int> a[N];
priority_queue<int,vector<int>,greater<int> > ql,qr;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++)
		a[i].first=read(),a[i].second=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
		if (a[i].first==(int)ql.size()) 
		ql.push(a[i].second),qr.push(ql.top()),ql.pop();
		else ql.push(a[i].second),ans++;
	for (int i=ql.size()+1;i<=m;i++)
		if (!qr.empty()&&qr.top()<=i) qr.pop(),ans++;
	printf("%d\n",n-ans);
	return 0;
}