//#include<stdio.h>
//#include<stdlib.h>
#include<bits/stdc++.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define MEM(x) memset(x,0,sizeof(x))
#define N 200005
#define pi 3.14159265359
using namespace std;
typedef long long LL;
int f[200005];
int Find(int a){
	if(f[a]==a)return a;
	return f[a]=Find(f[a]);
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    pii p[200005];
    for(int i=0;i<n;i++)
    scanf("%d %d",&p[i].x,&p[i].y);
    sort(p,p+n);
    int r=m,ans=0;
    priority_queue<int,vector<int>,greater<int> > pq;
    for(int i=0;i<200005;i++)
    f[i]=i;
	for(int i=0;i<n;i++){
		pq.push(p[i].y);
		if(pq.size()>p[i].x){
			int a=pq.top();
			pq.pop();
			int fa=Find(a);
			//printf("%d %d\n",a,fa);
			if(fa!=m+1){
				f[fa]=fa+1;
			}	
			else{
				ans++;
			}
		}
		else{
		int fa=Find(pq.size());
		if(fa!=m+1)
		f[fa]=fa+1;
		else
		ans++;
		}
	} 
	printf("%d\n",ans);
	return 0;
}