//by Judge
#include<bits/stdc++.h>
#define Rg register
#define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i)
#define ll long long
using namespace std;
const int inf=1e9+7;
const int M=1e5+3;
typedef int arr[M];
#ifndef Judge
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#endif
char buf[1<<21],*p1=buf,*p2=buf;
inline bool cmax(int& a,int b){return a<b?a=b,1:0;}
inline bool cmin(int& a,int b){return a>b?a=b,1:0;}
inline int read(){ int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
} char sr[1<<21],z[20];int CCF=-1,Z;
inline void Ot(){fwrite(sr,1,CCF+1,stdout),CCF=-1;}
inline void print(int x,char chr='\n'){
	if(CCF>1<<20)Ot();if(x<0)sr[++CCF]=45,x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++CCF]=z[Z],--Z);sr[++CCF]=chr;
} int n,m,ans,t[M<<2],Tag[M<<2]; vector<int> val[M];
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r
inline int Max(int x,int y){ return x>y?x:y; }
inline void pushup(int k){ t[k]=Max(t[ls],t[rs]); }
inline void pushdown(int k){ if(!Tag[k]) return ;
	Tag[ls]+=Tag[k],Tag[rs]+=Tag[k];
	t[ls]+=Tag[k],t[rs]+=Tag[k],Tag[k]=0;
}
void build(int k,int l,int r){
	if(l==r) return t[k]=l,void();
	build(lson),build(rson),pushup(k);
}
void update(int k,int l,int r,int L,int R){
	if(L<=l&&r<=R) return ++Tag[k],++t[k],void(); if(l>R||L>r) return ;
	pushdown(k),update(lson,L,R),update(rson,L,R),pushup(k);
}
int query(int k,int l,int r,int L,int R){
	if(L<=l&&r<=R) return t[k]; if(l>R||L>r) return 0;
	return pushdown(k),Max(query(lson,L,R),query(rson,L,R));
}
int main(){ int l,r; n=read(),m=read()+1,ans=n-m;
	fp(i,1,n) l=read(),r=read(),val[l].push_back(r);
	build(1,0,m);
	fp(L,0,m-1){
		fp(j,0,val[L].size()-1) update(1,0,m,0,val[L][j]);
		ans=Max(ans,query(1,0,m,L+1,m)-m-L);
	} return !printf("%d\n",ans);
}