#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2e5+50;
int n,m,a[N],ans;
vector<int>v[N];
priority_queue<int>q;
int main(){
    scanf("%d%d",&m,&n);
    for(int i=1,x,y;i<=m;i++)
        scanf("%d%d",&x,&y),v[y].pb(x);
    for(int i=n+1,j=n;i;i--)
        for(int k=0;k<v[i].size();k++){
            q.push(v[i][k]);
            if(j>=i)j--,ans++;
            else a[q.top()]++,q.pop();
        }
    for(int i=1,j=0;i<=n;i++){
        int dat=min(a[i],i-j);
        j+=dat;ans+=dat;
    }
    cout<<m-min(ans,n);
    return 0;
}