#include <cstdio>
#include <vector>
#include <queue>
#define pb push_back
std::priority_queue<int, std::vector<int>, std::greater<int> > que; 
std::vector<int> pos[200005]; 
int rem[200005];
int main()
{
	// freopen("ARC076-F.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m); 
	for (int i = 0; i < n; i++)
	{
		int l, r; 
		scanf("%d%d", &l, &r); 
		pos[l].pb(r); 
	}
	int l = 0; 
	for (int i = 0; i <= m; i++)
	{
		for (int x : pos[i])
		{
			if (l < i)
			{
				que.push(x); 
				l++; 
				continue; 
			}
			if (que.empty() || x <= que.top())
				rem[x]++; 
			else
			{
				rem[que.top()]++;
				que.pop(); 
				que.push(x); 
			}
		}
	}
	int r = m + 1, ans = rem[m + 1]; 
	for (int i = m; i; i--)
	{
		while (rem[i])
		{
			if (i < r && l + 1 < r)
				r--; 
			else
				ans++; 
			rem[i]--; 
		}
	}
	printf("%d\n", ans);
	return 0; 
}
