#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
pair<int,int>A[233333];int n,m,d;
priority_queue<int,vector<int>,greater<int>>q,v;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d%d",&A[i].first,&A[i].second);
	sort(A+1,A+n+1);
	for(int i=d=1;i<=n;++i)if(d<=m&&A[i].first>=d)q.push(A[i].second),++d;else q.push(A[i].second),v.push(q.top()),q.pop();
	for(int i=d;i<=m&&!v.empty();++i)if(i>=v.top())v.pop();
	printf("%d",v.size());return 0;
}