#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, L[200009], R[200009]; bool vis[200009]; vector<int> g[200009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> L[i] >> R[i];
		g[L[i]].push_back(i);
	}
	int ret = 0;
	priority_queue<int> que;
	for (int i = M + 1; i >= 0; i--) {
		for (int j : g[i]) que.push(R[j]);
		if (i != 0 && i != M + 1 && !que.empty()) {
			ret++;
			que.pop();
		}
	}
	fill(vis + 1, vis + ret + 1, true);
	vector<int> x;
	while (!que.empty()) x.push_back(que.top()), que.pop();
	int cur = 1;
	for (int i = x.size() - 1; i >= 0; i--) {
		cur = max(cur, x[i]);
		while (cur <= M && vis[cur]) cur++;
		if (cur > M) break;
		ret++; cur++;
	}
	cout << N - ret << endl;
	return 0;
}