#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  int N,M;cin>>N>>M;
  vector<vint> end(3*M+10);
  repeat(i,N){
    int L,R;cin>>L>>R;
    L+=M;
    end[R].push_back(L);
    end[R+M].push_back(L+M);
  }
  vll used(3*M+10);
  priority_queue<int> Q;
  ll mx=0;
  repeat(i,3*M){
    for(int e:end[i])Q.push(-e);
    while(!Q.empty()&&-Q.top()<i)Q.pop();
    if(i>0)used[i]=used[i-1];
    if(!Q.empty()){
      used[i]++;
      Q.pop();
    }
    if(i>M)mx=max(mx,used[i]-used[i-M]);
  }
  cout << N-mx<<endl;
  return 0;
}
