#include <bits/stdc++.h>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 2e5 + 10;

int n, m;
PII A[N];
int lim[N], c;

priority_queue<int, vector<int>, greater<int> > q;

int main(){
	
	scanf("%d%d", &n, &m);
	For(i, 1, n) scanf("%d%d", &A[i].x, &A[i].y);
	sort(A + 1, A + n + 1);

	int j = 0;
	For(i, 0, m){
		while(j < n && A[j + 1].x == i) q.push(A[++j].y);
		while(q.size() > i) lim[++c] = q.top(), q.pop();
	}
	int L = q.size(), ans = 0;

	For(i, 1, c) lim[i] = max(lim[i], L + 1);
	sort(lim + 1, lim + c + 1, greater<int>());

	j = 0;
	int now = 0;
	Forr(i, m + 1, L + 1){
		while(j < c && lim[j + 1] == i) ++now, ++j;
		if(now > m + 1 - i) ans += now - (m + 1 - i), now = m + 1 - i;
	}
	printf("%d\n", ans);

	return 0;
}