#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define F first
#define S second

ll n,m;
vector<pll> A;

bool judge(ll r){
    for(int i=0;i<n && r>0;i++){
        if(A[i].F>=r){r--;}
    }
    return r==0;
}

int main(){
    cin>>n>>m;
    A.resize(n);
    for(auto &I:A){cin>>I.F>>I.S;}
    sort(A.begin(),A.end(),greater<pll>());
    ll l=1,r=m+1;
    while(r-l>0){
        ll m=l+(r-l)/2;
        if(judge(m)){l=m+1;}
        else{r=m;}
    }
    l--;
    ll w=0;
    priority_queue<ll> Q;
    ll cnt=0;
    for(;l>0;l--){
        while(w<n && A[w].F>=l){Q.push(A[w].S); w++;}
        assert(!Q.empty());
        Q.pop();
        cnt++;
    }
    while(w<n){Q.push(A[w].S); w++;}
    w=m;
    while(!Q.empty() && w>=r){
        ll a=Q.top(); Q.pop();
        if(a<=w){w--; cnt++;}
    }
    cout<<n-cnt<<endl;
    
    
    return 0;
}
