#include<bits/stdc++.h>

int n,m,cl,cr,c,ans;
struct hito{int l,r;}p[200005];
bool operator<(hito a,hito b){return a.l<b.l;}

std::priority_queue<int,std::vector<int>,std::greater<int>>heap;
int q[200005];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
	scanf("%d%d",&p[i].l,&p[i].r);

    std::sort(p+1,p+n+1);

    for(int i=1;i<=n;++i)
    {
	heap.push(p[i].r),++cl;
	if(cl>p[i].l)q[++c]=heap.top(),heap.pop(),--cl;
    }

    std::sort(q+1,q+c+1,std::greater<int>());

    cr=m+1;
    for(int i=1;i<=c;++i)
	if(--cr<q[i])++ans,++cr;

    printf("%d\n",cl<cr?ans:n-m);
    
    return 0;
}