#include <algorithm>
#include <cstdio>
#include <queue>
const int N=200005;
struct info{int l,r;}a[N];
bool cmp(info a,info b){
	return a.l<b.l;
}
std::priority_queue<int> q;
int main(){
	int n,m,ans=0,cnt=0;
	scanf("%d%d\n",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d\n",&a[i].l,&a[i].r);
	std::sort(a+1,a+n+1,cmp);
	for (int i=m,j=n;i>=0;i--){
		for (;j && a[j].l==i;j--) q.push(a[j].r);
		if (i && !q.empty()) q.pop(),cnt++;
	}
	for (int i=m;i>cnt && !q.empty();){
		if (q.top()<=i) i--;
			else ans++;
		q.pop();
	}
	printf("%d\n",ans+q.size());
}