#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=2e5+10;
int n,m;
int L[N],R[N];
priority_queue<int> Q;
int id[N];
inline bool cmp(int i,int j){return L[i]<L[j]||(L[i]==L[j]&&R[i]>R[j]);}
int stk[N],top=0;
int main()
{
	init(n),init(m);
	for(int i=1;i<=n;++i) init(L[i]),init(R[i]),id[i]=i;
	sort(id+1,id+1+n,cmp);int h=1;
	int mat=0;
	for(int i=1;i<=n;++i) {
		int u=id[i];
		if(L[u]>=h&&h<=m) Q.push(-R[u]),++h,++mat;
		else if(!Q.empty()){
			int r=-Q.top();
			if(R[u]<=r) stk[++top]=R[u];
			else Q.pop(),Q.push(-R[u]),stk[++top]=r;
		}else stk[++top]=R[u];
	}
	sort(stk+1,stk+1+top);reverse(stk+1,stk+1+top);
	int t=m;
	for(int i=1;i<=top;++i) if(t>=h&&stk[i]<=t) --t,++mat;
	printf("%d\n",n-mat);
}
