#include <bits/stdc++.h>
using namespace std;
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
int N, M;
int L[100010];
int R[100010];
bool used[300010];
vector<int> cnd[300010];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> L[i] >> R[i];
  vector<pair<int, int> > ord;
  for (int i = 0; i < N; i++) {
    cnd[R[i]].push_back(L[i] + M);
    cnd[R[i] + M].push_back(L[i] + 2 * M);
  }
  int cnt = 0;
  int ans = 0;
  reversed_priority_queue<int> pos;
  for (int i = 0; i < 300000; i++) {
    for (int j = 0; j < (int)cnd[i].size(); j++) {
      pos.push(cnd[i][j]);
    }
    while (!pos.empty()) {
      if (pos.top() < i) {
        pos.pop();
      } else {
        break;
      }
    }
    if (!pos.empty()) {
      used[i] = true;
      cnt++;
      pos.pop();
    }
    if (i - M >= 0) {
      if (used[i - M]) {
        cnt--;
      }
    }
    ans = max(ans, cnt);
  }
  cout << N - ans << endl;
  return 0;
}
