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

vector<int>vec[201000];
int n,m,x,y,ans,t;
priority_queue<int>q;

int main(){
  cin.tie(0);
  cin>>n>>m;
  for (int i=n;i--;) cin>>x>>y, vec[x].push_back(y);
  for (int i=m;~i;--i){
    for (auto o:vec[i]) q.push(o);
    if (i&&!q.empty())
      q.pop(), ++t;
  }
  ans=t; y=m;
  for (;!q.empty();){
    x=q.top(); q.pop();
    if (x<=y&&y>t) ++ans, --y;
  }
  cout<<n-ans<<endl;
}
