#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;

struct info{
	int l,r;
	bool operator < (const info &B) const{
		return l<B.l||l==B.l&&r>B.r;
	}
} s[N];

priority_queue<int,Vi,greater<int> > Q;

int n,m,c,ans;

int main(){
	n=IN(),m=IN();
	For(i,1,n+1) s[i]=(info){IN(),IN()};
	sort(s+1,s+n+1);
	c=1;
	For(i,1,m+1){
		for (;c<=n&&s[c].l<i;c++) Q.push(s[c].r);
		if (c<=n){
			ans++;
			c++;
		} lf (!Q.empty()&&Q.top()<=i){
			Q.pop();
			ans++;
		}
	}
	printf("%d\n",n-ans);
}