#include<cstdio>
#include<queue>
using namespace std;
const int N=2e5+5;
int n,m,i,he[N],cnt,now,ans;
struct edge{int l,to;}e[N];
priority_queue<int> q;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	for (n=read(),m=read(),i=1;i<=n;i++){
		int x=read(),y=read();
		e[i].l=he[x];he[x]=i;e[i].to=y;
	}
	for (int x=m;~x;x--){
		for (i=he[x];i;i=e[i].l) q.push(e[i].to);
		if (x&&!q.empty()) q.pop(),cnt++;
	}
	ans=cnt;now=m;
	for (;!q.empty()&&now>cnt;q.pop())
		if (q.top()<=now) ans++,now--;
	printf("%d",n-ans);
}