#include<bits/stdc++.h>
using namespace std;

#define fir first
#define sec second
int n,m,ans,p,q;
pair<int,int> a[200005];

int main()
{
    scanf("%d %d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d %d",&a[i].fir,&a[i].sec);
    sort(a+1,a+1+n,[](auto x,auto y) {return x.sec==y.sec ? (x.fir<y.fir) : (x.sec>y.sec);});
    p=0; q=m+1;
    //for (int i=1;i<=n;i++) printf("*%d %d\n",a[i].fir,a[i].sec);
    for (int i=1;i<=n;i++)
    {

        if (q==p+1) ans++;
        else if (a[i].fir>p) p++;
        else if (a[i].sec<q) q--;
        else ans++;
        //printf("*%d %d %d\n",a[i].fir,a[i].sec,ans);
    }
    printf("%d\n",ans);
    return 0;
}