#include <queue>
#include <cstdio>
#include <vector>

int n,m,Ans,t,x,y;
std::vector<int> v[200005];
std::priority_queue<int> q;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)scanf("%d%d",&x,&y),v[x].push_back(y);
    for(int i=m;i>=0;--i)
    {
        for(auto j:v[i])q.push(j);
        if(i&&!q.empty())q.pop(),++t;
    }
    Ans=t,y=m;
    while(!q.empty())
    {
        x=q.top(),q.pop();
        if(x<=y&&y>t)++Ans,--y;
    }
    printf("%d\n",n-Ans);
    return 0;
}