// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=200000+10;

int n,m;
struct node { int l,r; } a[N];
priority_queue<int,vector<int>,greater<int>> L;
priority_queue<int> R;

int main() {
	n=read(),m=read();
	for (int i=1;i<=n;++i) a[i].l=read(),a[i].r=read();
	sort(a+1,a+n+1,[](node a,node b) { return a.l<b.l; });
	int l=1,r=m,ans=0;
	for (int i=1;i<=n;++i) {
		L.push(a[i].r);
		if (l<=r&&l<=a[i].l) ++l;
		else R.push(L.top()),L.pop();
	}
	while (!R.empty()) {
		if (l<=r&&r>=R.top()) --r;
		else ++ans;
		R.pop();
	}
	printf("%d\n",ans);
	return 0;
}