#include<bits/stdc++.h>
#define l first
#define r second
using namespace std;
pair<int,int> a[200010];
priority_queue<int,vector<int>,greater<int> > ql,qr;
int main()
{
	int n,m,rem;scanf("%d%d",&n,&m);rem=n;
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
		if (a[i].l==ql.size()) {ql.push(a[i].r);qr.push(ql.top());ql.pop();}
		else {ql.push(a[i].r);rem--;}
	for (int i=ql.size()+1;i<=m;i++) if ((!qr.empty())&&(qr.top()<=i)) {rem--;qr.pop();}
	printf("%d\n",rem);
}