#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int> >g;
vector<int>v;
priority_queue<int>pq;
int main()
{
	scanf("%d%d",&n,&m);
	g.clear();
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		g.push_back(make_pair(l,r));
	}
	sort(g.begin(),g.end());
	int num=0;
	for(int i=0;i<n;i++)
	{
		pq.push(-g[i].second);
		int x=g[i].first;
		if(x>num)num++;
		else
		{
			v.push_back(pq.top());
			pq.pop();
		}
	}
	sort(v.begin(),v.end());
	int pos=num,ans=0;
	num=0;
	for(int i=0;i<v.size();i++)
	{
		if(m-num<(-v[i]))ans++;
		else if(pos+num==m)ans++;
		else num++;
	}
	printf("%d\n",ans);
	return 0;
} 