#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n, m, w[301000], s, M, P[201000], cnt;
vector<int>E[201000];
priority_queue<int>PQ;
int main() {
	int i, b, e, j;
	scanf("%d%d", &n,&m);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &b, &e);
		E[b].push_back(e);
	}
	for (i = 0; i <= m; i++) {
		for (j = 0; j < E[i].size(); j++) {
			PQ.push(-E[i][j]);
		}
		while (PQ.size() > i) {
			P[cnt++] = -PQ.top();
			PQ.pop();
		}
	}
	int s = 0, r = PQ.size(), sz = PQ.size();
	for (i = 0; i < cnt; i++) {
		P[i] = max(P[i], sz + 1);
		w[P[i]]++;
	}
	for (i = m; i > sz; i--) {
		s++;
		r += min(s, w[i]);
		s -= min(s, w[i]);
	}
	printf("%d\n", n - r);
}