#include <bits/stdc++.h>
using namespace std;
int N, R;
bool used[400005];
vector<int> V[400005], V2[400005];
vector<pair<int, int> > V3[400005], V4[400005];
vector<pair<pair<int, int>, int> > V5[400005], V6[400005];
priority_queue<int, vector<int>, greater<int> > PQ;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    PQ2;
priority_queue<pair<pair<int, int>, int> > PQ3;
int main() {
  scanf("%d%d", &N, &R);
  for (int i = 0; i < N; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    V[r].push_back(l + R);
    int newl = R - r + 1;
    int newr = R - l + 1;
    V2[newr].push_back(newl + R);
    V3[1].push_back(make_pair(l, i));
    V3[r].push_back(make_pair(R, i));
    V4[1].push_back(make_pair(newl, i));
    V4[newr].push_back(make_pair(R, i));
    V5[1].push_back(make_pair(make_pair(r, l), i));
    V5[r].push_back(make_pair(make_pair(-1000000000, R), i));
    V6[1].push_back(make_pair(make_pair(r, newl), i));
    V6[newr].push_back(make_pair(make_pair(-1000000000, R), i));
  }
  int ans = N;
  for (int i = max(1, R / 10); i <= R * 2; i++) {
    if (i > R && used[i - R]) continue;
    for (int j = 0; j < V[i].size(); j++) PQ.push(V[i][j]);
    while (!PQ.empty() && PQ.top() < i) PQ.pop();
    if (!PQ.empty()) {
      PQ.pop();
      ans--;
      used[i] = 1;
    }
  }
  while (!PQ.empty()) PQ.pop();
  int ans2 = N;
  memset(used, 0, sizeof(used));
  for (int i = max(1, R / 10); i <= R * 2; i++) {
    if (i > R && used[i - R]) continue;
    for (int j = 0; j < V2[i].size(); j++) PQ.push(V2[i][j]);
    while (!PQ.empty() && PQ.top() < i) PQ.pop();
    if (!PQ.empty()) {
      PQ.pop();
      ans2--;
      used[i] = 1;
    }
  }
  while (!PQ.empty()) PQ.pop();
  memset(used, 0, sizeof(used));
  int ans3 = N;
  for (int i = 1; i <= R; i++) {
    for (int j = 0; j < V3[i].size(); j++) {
      if (used[V3[i][j].second]) continue;
      PQ2.push(V3[i][j]);
    }
    while (!PQ2.empty() && PQ2.top().first < i) PQ2.pop();
    if (!PQ2.empty()) {
      used[PQ2.top().second] = 1;
      PQ2.pop();
      ans3--;
    }
  }
  while (!PQ2.empty()) PQ2.pop();
  memset(used, 0, sizeof(used));
  int ans4 = N;
  for (int i = 1; i <= R; i++) {
    for (int j = 0; j < V4[i].size(); j++) {
      if (used[V4[i][j].second]) continue;
      PQ2.push(V4[i][j]);
    }
    while (!PQ2.empty() && PQ2.top().first < i) PQ2.pop();
    if (!PQ2.empty()) {
      used[PQ2.top().second] = 1;
      PQ2.pop();
      ans4--;
    }
  }
  memset(used, 0, sizeof(used));
  int ans5 = N;
  for (int i = 1; i <= R; i++) {
    for (int j = 0; j < V5[i].size(); j++) {
      if (used[V5[i][j].second]) continue;
      PQ3.push(V5[i][j]);
    }
    while (!PQ3.empty() && PQ3.top().first.second < i) PQ3.pop();
    if (!PQ3.empty()) {
      used[PQ3.top().second] = 1;
      PQ3.pop();
      ans5--;
    }
  }
  while (!PQ3.empty()) PQ3.pop();
  int ans6 = N;
  for (int i = 1; i <= R; i++) {
    for (int j = 0; j < V6[i].size(); j++) {
      if (used[V6[i][j].second]) continue;
      PQ3.push(V6[i][j]);
    }
    while (!PQ3.empty() && PQ3.top().first.second < i) PQ3.pop();
    if (!PQ3.empty()) {
      used[PQ3.top().second] = 1;
      PQ3.pop();
      ans6--;
    }
  }
  printf("%d\n", min(min(ans, min(ans4, min(ans5, ans6))), min(ans2, ans3)));
}
