#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, m;
pp h[200010];

int main()
{
	read(n, m);
	for(int i=1; i<=n; ++i) read(h[i].x, h[i].y);
	sort(h+1, h+n+1);
	multiset<int> rs;
	multiset<int> down;
	for(int i=1; i<=n; ++i){
		int x = h[i].x;
		rs.insert(h[i].y);
		while(int(rs.size()) > x){
			down.insert(*rs.begin());
			rs.erase(rs.begin());
		}
	}
	int ans = 0;
	int ind = m;
	int rss = rs.size();
	for(auto it=down.end(); it!=down.begin();){
		int x=*--it;
		if(ind > rss && x <= ind) --ind;
		else ++ans;
	}
	printf("%d\n", ans);
	return 0;
}
