#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 200005;

int n,m;
PII a[N];
int cnt=0,b[N];
priority_queue<int> Q;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),m=read();
	rep(i,1,n) a[i].first=read(),a[i].second=read();
	sort(a+1,a+n+1);
	int ans=0;
	rep(i,1,n) {
		Q.push(-a[i].second);
		if ((int)Q.size()>a[i].first) b[++cnt]=-Q.top(),Q.pop();
	}
	ans=Q.size();
	sort(b+1,b+cnt+1);
	int L=ans,R=m;
	per(i,cnt,1) {
		if (L==R) break;
		if (R>=b[i]) R--;
	}
	ans+=m-R;
	printf("%d\n",n-ans);

	return 0;
}
