#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,m;
vector<int>vec[N];
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		if(x)vec[x].push_back(y);else q.push(y);
	}
	for(int i=1;i<=m+1;i++)sort(vec[i].begin(),vec[i].end());
	int pos=-1;
	for(int i=1;i<=m;i++)
	if(vec[i].size()>1)
	for(int j=0;j<vec[i].size()-1;j++)q.push(vec[i][j]);
	else if(!vec[i].size())
	{
		if(!q.empty()&&q.top()<=i)q.pop();
		else{
			pos=max(pos,i);
			while(!vec[pos].size()&&pos<=m)pos++;
			if(vec[pos].size())vec[pos].pop_back();
		}
	}
	printf("%d",q.size());
}
