#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];
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++) {
    ord.push_back(make_pair(L[i] + M, R[i]));
    ord.push_back(make_pair(L[i] + 2 * M, R[i] + M));
  }
  int idx = 0;
  sort(ord.begin(), ord.end());
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < 300010; i++) {
    while (idx < ord.size()) {
      if (ord[idx].first < i) {
        idx++;
      } else {
        break;
      }
    }
    if (ord[idx].second >= i) {
      used[i] = true;
      cnt++;
      idx++;
    }
    if (i - M >= 0) {
      if (used[i - M]) {
        cnt--;
      }
    }
    ans = max(ans, cnt);
  }
  cout << N - ans << endl;
  return 0;
}
