#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
vector<int> R[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1,l,r;i<=n;i++) {
		cin >> l >> r;
		R[l].push_back(r);
	}
	priority_queue<int> L_pq,tem;
	for(int i=m;i>=1;i--) {
		for(int r : R[i])
			tem.push(r);
		if(!tem.empty()) {
			L_pq.push(-tem.top());
			tem.pop();
		}
	}
	for(int r : R[0])
		tem.push(r);
	set<int> wait;
	for(int i=1;i<=m;i++)
		wait.insert(i);
	while(!tem.empty()) {
		int now = tem.top();
		tem.pop();
		auto it = wait.lower_bound(now);
		if(it != wait.end())
			wait.erase(it);
	}
	int ans = (int)L_pq.size() + min(m - (int)L_pq.size(),m - (int)wait.size());
	while(!L_pq.empty()) {
		int r = -L_pq.top();
		L_pq.pop();
		auto it = wait.lower_bound(r);
		if(it != wait.end())
			wait.erase(it);
		ans = max(ans,(int)L_pq.size() + min(m - (int)L_pq.size(),m - (int)wait.size()));
	}
	cout << n - ans << endl;
	return 0;
}
