#include <iostream>
#include <vector>
#include <functional>
#include <queue>
using namespace std;

int N, M, L[200009], R[200009];
vector<int>vec[200009];
priority_queue<int, vector<int>, greater<int>>Q;

int main() {
	cin >> N >> M; M++;
	for (int i = 1; i <= N; i++) {
		cin >> L[i] >> R[i]; vec[L[i]].push_back(R[i]);
	}
	for (int i = M; i > N; i--) {
		for (int j : vec[i]) Q.push(M - j);
	}
	int P = M - 1;
	for (int i = N; i >= 1; i--) {
		for (int j : vec[i]) Q.push(M - j);
		if (!Q.empty()) { Q.pop(); P--; }
	}
	for (int j : vec[0]) Q.push(M - j);

	vector<int>v; while (!Q.empty()) { v.push_back(Q.top()); Q.pop(); }
	int B = 1, cnt = v.size();
	for (int i = 0; i < v.size(); i++) {
		if (B > P) break;
		if (B <= v[i]) { B++; cnt--; }
	}
	cout << cnt << endl;
	return 0;
}