#include<bits/stdc++.h>
using namespace std;
const int mxn=200005;
#define init int nd, int cl, int cr
#define md (cl+cr)/2
#define lnd nd*2
#define rnd nd*2+1
#define lc lnd, cl, md
#define rc rnd, md+1, cr
int n, m, st[mxn*4], lz[mxn*4];
vector<int>ins[mxn];
void build(init){
	st[nd]=cl;
	if(cl==cr) return;
	build(lc); build(rc);
	st[nd]=min(st[lnd], st[rnd]);
}
void pro(int nd){
	if(!lz[nd]) return;
	st[lnd]+=lz[nd], lz[lnd]+=lz[nd];
	st[rnd]+=lz[nd], lz[rnd]+=lz[nd];
	lz[nd]=0;
}
void upd(init, int l, int r){
	if(r<cl || cr<l) return;
	if(l<=cl && cr<=r){
		st[nd]--; lz[nd]--;
		return;
	}
	pro(nd);
	upd(lc, l, r); upd(rc, l, r);
	st[nd]=min(st[lnd], st[rnd]);
}
int que(init, int l, int r){
	if(r<cl || cr<l) return INT_MAX;
	if(l<=cl && cr<=r) return st[nd];
	pro(nd);
	return min(que(lc, l, r), que(rc, l, r));
}
int main(){
	scanf("%d%d", &n, &m); m++;
	for(int i=1, u, v; i<=n; i++){
		scanf("%d%d", &u, &v);
		v=m-v;
		ins[u].push_back(v);
	}
	build(1, 0, m);
	int ans=m-1-n;
	for(int i=0; i<=m; i++){
		for(int j=0; j<ins[i].size(); j++){
			int pos=ins[i][j];
			upd(1, 0, m, pos, m);
		}
		ans=min(ans, i+que(1, 0, m, 0, m-i));
	}
	printf("%d\n", max(0, -ans));
	return 0;
}