#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int maxn=200005;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,cur=0,now;
typedef pair<int,int> P;
P a[maxn];
priority_queue<int,vector<int>,greater<int> > que;
vector<int> vec;
int main(){
	n=read(),m=read();now=m+1;
	for (int i=1;i<=n;++i) a[i].fi=read(),a[i].se=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;++i){
		que.push(a[i].se);
		if (cur==a[i].fi){
			vec.push_back(que.top());
			que.pop();
		}
		else ++cur;
	}
	sort(vec.begin(),vec.end());
	for (int i=vec.size()-1;i>=0&&now>cur+1;--i){
		if (now==vec[i]) continue;
		--now;
	}
	printf ("%d\n",n-m+now-cur-1);
	return 0;
}
