#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair

struct Point {
	int x, y, id;

	Point() {}

	Point(int x, int y) : x(x), y(y) {}

	bool operator < (const Point & p) {
		if (y != p.y)
			return y < p.y;
		if (x != p.x)
			return x < p.x;
		return id < p.id;
	}
};

const int N = 2e5 + 10;

Point p[N];

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	int n, m;
	cin >> n >> m;
	set<int> setik;
	for (int i = 1; i <= 2 * m; i++)
		setik.insert(i);
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		p[i] = Point(r, l + m);
		p[i].id = i;
	}
	sort(p, p + n);
	int res = n;
	for (int i = 0; i < n; i++) {
		int x = p[i].x;
		int y = p[i].y;
		//cout << x << " " << y << " ";
		auto it = setik.lower_bound(x);
		if (it == setik.end() || (*it) > y)
			continue;
		int t = (*it);
		res--;
		setik.erase(t);
		if (t <= m)
			setik.erase(t + m);
		else
			setik.erase(t - m);
	}
	cout << res << endl;
	return 0;
}