#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

struct data{
	int l,r;
	data():l(0),r(0){}
	data(int x,int y):l(x),r(y){}
	friend bool operator<(const data &dt1,const data &dt2){if(dt1.l==dt2.l)return dt1.r>dt2.r;return dt1.l<dt2.l;}
};

vector<int> vec;
priority_queue<int,vector<int>,greater<int>> pq;
int n,m,ans;
data a[200001];

int main(){
	scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1);
	int head=1,tail=m;
	for(int i=1;i<=n;++i){
		pq.push(a[i].r);
		if(head<=tail&&head<=a[i].l)++head;else vec.push_back(pq.top()),pq.pop();
	}
	sort(vec.begin(),vec.end());
	for(int i=vec.size()-1;~i;--i)if(head<=tail&&vec[i]<=tail)--tail;else ++ans;
	printf("%d",ans);
}