#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
using namespace std;
int l[200010], r[200010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin>>N>>M;
    rep(i,0,N){
        int 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;
    int 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(0,N-min(ans,M))<<"\n";
}