#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int MAXN = 200005;
int n, m, pre, suf;
pair<int ,int> s[MAXN];
vector<int> a;
priority_queue< int, vector<int>, greater<int> > q;
#define fi first
#define se second
#define MP make_pair

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &s[i].fi, &s[i].se);
	sort(s + 1, s + n + 1);
	
	for(int i = 1; i <= n; ++i)
	if(q.size() < s[i].fi) q.push(s[i].se);
	else if(!q.empty() && q.top() < s[i].se) a.push_back(q.top()), q.pop(), q.push(s[i].se);
	else a.push_back(s[i].se);
	
	pre = q.size();
	sort(a.begin(), a.end(), greater<int>());
	for(int i = 0; i < a.size(); ++i) if(suf + 1 <= min(m + 1 - a[i], m - pre)) ++suf;
	
	printf("%d\n", n - pre - suf);
	
	return 0;
}