#include<bits/stdc++.h>
 
using lint = long long int;
using pii = std::pair<int, int>;
 
using std::vector;
using std::priority_queue;
 
vector<pii> ve;
vector<int> ve2;
priority_queue<int, vector<int>, std::greater<int> > pq;
 
int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		ve.push_back(pii(t1, t2));
	}
 
	sort(ve.begin(), ve.end());
 
	int cou = 0;
	for (int i = 0; i < N; i++) {
		pq.push(ve[i].second);
		if (ve[i].first <= cou) {
			ve2.push_back(pq.top());
			pq.pop();
		}
		else {
			cou++;
		}
	}
 
	sort(ve2.begin(), ve2.end(), std::greater<int>());
 
	int cou2 = cou;
	cou = 0;
	int ans = 0;
	for (int i = 0; i < ve2.size(); i++) {
		if (M - cou == cou2) {
			ans++;
		}
		else if (M + 1 - ve2[i] <= cou) {
			ans++;
		}
		else {
			cou++;
		}
	}
 
	printf("%d", ans);
 
	return 0;
}