#include<stdio.h>
#include<algorithm>
using namespace std;

struct ss {
	int l, r;
} ba[302020];

bool comp1(const int& x, const int& y){
	if(ba[x].l != ba[y].l) return ba[x].l < ba[y].l;
	return ba[x].r < ba[y].r;
}

bool comp2(const int& x, const int& y){
	return ba[x].r < ba[y].r;
}

int N, M, idx[302020], lmx, chk[302020], rmx;

int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++){
		int s, e;
		scanf("%d%d", &s, &e);
		ba[i].l = s, ba[i].r = M+1-e;
		idx[i]=i;
	}
	sort(idx, idx+N, comp1);
	for(int i=0; i<N; i++){
		if(ba[idx[i]].l >= lmx+1) lmx++, chk[idx[i]]=1;
	}
	sort(idx, idx+N, comp2);
	for(int i=0; i<N; i++){
		if(chk[idx[i]]) continue;
		if(ba[idx[i]].r >= rmx+1) rmx++, chk[idx[i]]=1;
	}

	int dap = lmx+rmx;
	if(dap > M) dap = M;
	printf("%d", max(N-dap,0));
	return 0;
}