#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;cin>>N>>M;
  vector<vll> end(3*(M+1));
  for(ll i=0;i<N;i++){
    ll L,R;cin>>L>>R;
    L+=M;
    end[R].push_back(L);
    end[R+M].push_back(L+M);
  }
  priority_queue<ll> Q;
  vll done(3*(M+1),0);
  ll ma=0;
  for(ll i=0;i<3*(M+1);i++){
    //debug(i);
    for(ll e:end[i])Q.push(-e);
    while(!Q.empty()&&-Q.top()<i)Q.pop();
    if(i>0)done[i]=done[i-1];
    if(!Q.empty()){
      done[i]++;
      Q.pop();
    }
    if(i>=M){
      ma=max(ma,done[i]-done[i-M]);
    }
    //debug(done[i]);
  }
  cout<<N-ma<<endl;
  return 0;
}
