#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;
#define N 200127
int n,m,ans=0,L,R,s[N];
vector<int>a[N];
priority_queue<int,vector<int>,greater<int> >h;
int main(){
	scanf("%d%d",&n,&m);int i,x,y;
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
	}
	for(i=1;i<=m;i++)
	for(auto v:a[i])
	{
		if(L<i){++L;h.push(v);continue;}
		x=h.top();if(x>=v)++s[v];else {h.pop();++s[x];h.push(v);}
	}
	for(auto v:a[0])++s[v];ans=s[m+1];
	R=m+1;for(i=m;i>=1;i--)
	while(s[i]){if((i<R)&&(L+1<R))--R;else ++ans;--s[i];}
	printf("%d",ans);return 0;
}