#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int N, M;
int L[200100], R[200100];
priority_queue<int, vector<int>, greater<int> > pq;
int idx1[200100];
int up[200010];
int upL;
int res;

int cmp1(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	return L[i1] - L[i2];
}

void solve()
{
	int i;
	for(i=0; i<N; i++)
		idx1[i] = i;
	qsort(idx1, N, sizeof(int), cmp1);
	res = 0;
	int cur = 1;
	upL = 0;
	for(i=0; i<N; i++){
		if(cur <= L[idx1[i]]){
			cur ++;
			pq.push(R[idx1[i]]);
			res ++;
		}
		else{
			pq.push(R[idx1[i]]);
			up[upL] = pq.top() ;
			pq.pop() ;
			upL ++; 
		}
	}
	int lowpos = cur;
	sort(up, up+upL, greater<int>() );
	cur = M;
	for(i=0; i<upL; i++){
		if(cur < lowpos)
			break;
		if(cur >= up[i]){
			cur --;
			res ++;
		}
	}
	printf("%d\n", N-res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d%d", &N, &M);
	for(i=0; i<N; i++){
		scanf("%d%d", &L[i], &R[i]);
		/*if(L[i] == 0)
			L[i] = 1;
		if(R[i] > M)
			R[i] = M;*/
	}
	solve();
	return 0;
}