#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define MN 200005
using namespace std;
vector<int>a[MN];
int l[MN],r[MN],n,m;
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&l[i],&r[i]),a[l[i]].push_back(r[i]);
		if(l[i]==0)q.push(r[i]);
	}
	for(int i=1;i<=m;i++)sort(a[i].begin(),a[i].end());int pos=0;
	for(int i=1;i<=m;i++){
		if(a[i].size())for(int j=0;j<a[i].size()-1;j++)q.push(a[i][j]);
		else {
			if(!q.empty()&&q.top()<=i)q.pop();
			else {
				pos=max(pos,i);
				while(!a[pos].size()&&pos<=m)pos++;
				a[pos].pop_back();
			}
		}
	}printf("%d\n",q.size());
}