#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;

int n, m, rest[N];
vector<int> query[N];
priority_queue<int, vector<int>, greater<int> > heap;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		query[l].push_back(r);
	}
	int l = 0;
	for (int i = 0; i <= m; ++i)
		for (int _i = 0; _i < query[i].size(); ++_i) {
			int x = query[i][_i];
			if (l < i) {
				heap.push(x);
				++l;
				continue;
			}
			if (heap.empty() || x <= heap.top()) ++rest[x];
			else {
				++rest[heap.top()];
				heap.pop();
				heap.push(x);
			}
		}
	int r = m + 1, ans = rest[m + 1];
	for (int i = m; i; --i)
		while (rest[i]) {
			if (i < r && l + 1 < r) --r;
			else ++ans;
			--rest[i];
		}
	printf("%d\n", ans);
}