#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 2e5 + 5 ;
using namespace std ;

struct poi {
	int l, r ;
} a[N] ;
int n, m, p[N], d[N], top, ans ;

bool cmp(poi a, poi b) {
	return a.l < b.l ;
}

void push(int x) {
	p[top ++] = x ;
	push_heap(p, p + top) ;
}

void pop() {
	pop_heap(p, p + top) ; -- top ;
}

int main() {
	scanf("%d%d", &n, &m) ;
	rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r) ;
	sort(a + 1, a + n + 1, cmp) ;
	top = 0 ;
	rep(i, 1, n) {
		if (top + 1 <= a[i].l) push(- a[i].r) ; else 
			if (!a[i].l) d[++ d[0]] = a[i].r ; else {
				if (- p[0] < a[i].r) d[++ d[0]] = - p[0], pop(), push(- a[i].r) ; else d[++ d[0]] = a[i].r ;
			}
	}
	sort(d + 1, d + d[0] + 1) ;
	int tmp = top ; top = m, ans = 0 ;
	for (int i = d[0] ; i; -- i) {
		if (d[i] <= top && top > tmp) -- top ; else ++ ans ;
	}
	printf("%d\n", ans) ;
	return 0 ; 
}