#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
int l[200010], r[200010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin>>N>>M;
    rep(i,0,N){
        ll L,R;
        cin>>L>>R;
        if(L) l[L-1]++;
        if(R<=M) r[R-1]++;
    }
    rer(i,M-1,0){
        l[i]+=l[i+1];
    }
    rep(i,1,M){
        r[i]+=r[i-1];
    }
    int res=1e8;
    ll ans=0;
    rep(i,0,M){
        res=min(res-1,l[i]);
        if(res==0){
            ans=i;
            break;
        }
        if(i==M-1) ans=M;
    }
    res=1e8;
    rep(i,0,M){
        res=min(res-1,r[M-1-i]);
        if(res==0){
            ans+=i;
            break;
        }
        if(i==M-1) ans+=M;
    }
    cout <<max(0LL,N-min(ans,M))<<"\n";
}