#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#define N 201000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
int n, m;
struct node {
	int l, r;
	inline bool operator <(const node &a) const {
		return l < a.l || (l == a.l && r < a.r);
	}
}nd[N];
bool vis[N];
priority_queue<int, vector<int>, greater<int> > q;
int h[N], htot;
bool cmp(const int x, const int y) {
	return x > y;
}
int main() {
	read(n); read(m);
	for (int i = 1; i <= n; ++i)	read(nd[i].l), read(nd[i].r);
	sort(nd + 1, nd + 1 + n);
	int ptr = 1;
	for (int i = 1; i <= n; ++i) {
		int l = nd[i].l;
		if (ptr <= m && l >= ptr)	vis[ptr] = true, ++ptr, q.push(nd[i].r);
		else {
			q.push(nd[i].r); h[++htot] = q.top(); q.pop();
		}
	}
	sort(h + 1, h + 1 + htot, cmp);
	ptr = m;
	while (ptr && vis[ptr])	--ptr;
	int ct = 0;
	for (int i = 1; i <= htot; ++i) {
		int r = h[i];
		if (ptr && r <= ptr) {
			vis[ptr] = true;
			--ptr;
			while (ptr && vis[ptr])	--ptr;
		} else ++ct;
	}
	printf("%d\n", ct);
	return 0;
}
