#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

const int Inf = 0x3f3f3f3f, MaxN = 200005;

typedef pair<int, int> Interval;
Interval p[MaxN];

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

int main()
{
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	for (int i = 1; i <= N; i++)
		cin >> p[i].first >> p[i].second;
	sort(p + 1, p + N + 1, [](const Interval &a, const Interval &b) -> bool {
		return a.first == b.first ? a.second > b.second : a.first < b.first;
	});
	int now = 0;
	for (int i = 1; i <= N; i++)
	{
		if (p[i].first)
			break;
		now = i;
		Heap.push(p[1].second);
	}
	int Ans = 0;
	for (int i = 1; i <= M; i++)
	{
		for (; now < N && p[now + 1].first < i; Heap.push(p[++now].second))
			;
		if (now < N)
			++now;
		else
		{
			if (!Heap.empty() && Heap.top() <= i)
				Heap.pop();
			else
				continue;
		}
		if (++Ans == N)
			break;
	}
	cout << N - Ans << endl;
	return 0;
}