#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

int n,m,ans=0,tmp[200005];
struct Student{
    int l,r;
    bool operator<(const Student &b)const{
        return l!=b.l?l<b.l:r>b.r;
    }
}s[200005];
priority_queue<int,vector<int>,greater<int> > q;

int main(){
//  freopen("data.in","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&s[i].l,&s[i].r);
    sort(s+1,s+n+1);
    int h=1,t=m;
    for(int i=1;i<=n;i++){
        q.push(s[i].r);
        if(h<=t&&h<=s[i].l)h++;
        else{
            tmp[++tmp[0]]=q.top();
            q.pop();
        }
    }
    sort(tmp+1,tmp+tmp[0]+1);
    for(int i=tmp[0];i>=1;i--){
        if(h<=t&&tmp[i]<=t)t--;
        else ans++;
    }
    printf("%d",ans);
}
// I am exhausted.