#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#define MN 200000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
vector<int> v[MN+5];
int n,l[MN+5],b[MN+5],r[MN+5],ans=0,m;
priority_queue<int> q;
inline void Move(int&R){for(;R&&b[R];--R);}
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i) l[i]=read(),r[i]=read(),v[l[i]].push_back(i);
	for(int i=m;~i;--i)
	{
		for(int j=0;j<v[i].size();++j) q.push(r[v[i][j]]);
		if(i&&q.size()) q.pop(),++ans;	
	}
	int R=m,t=m-ans;
	while(q.size())
	{
		if(q.top()<=R&&t) --t,--R,++ans; 
		q.pop();
	}
	cout<<n-ans;
	return 0;
}

