#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
const int inf = 1e9 + 7;
struct Node {
  int add, mi;
  Node() { add = mi = 0; }
} tr[N * 12];
void down(int o) {
  if (tr[o].add) {
    tr[o << 1].add += tr[o].add;
    tr[o << 1 | 1].add += tr[o].add;
    tr[o << 1].mi += tr[o].add;
    tr[o << 1 | 1].mi += tr[o].add;
    tr[o].add = 0;
  }
}
void up(int o) { tr[o].mi = min(tr[o << 1].mi, tr[o << 1 | 1].mi); }
void setValue(int o, int l, int r, int ql, int value) {
  if (l + 1 == r) {
    tr[o].mi = value;
  } else {
    int mid = l + r >> 1;
    down(o);
    if (ql < mid)
      setValue(o << 1, l, mid, ql, value);
    else
      setValue(o << 1 | 1, mid, r, ql, value);
    up(o);
  }
}
void update(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    tr[o].add++;
    tr[o].mi++;
  } else {
    int mid = l + r >> 1;
    down(o);
    if (ql < mid) update(o << 1, l, mid, ql, qr);
    if (qr > mid) update(o << 1 | 1, mid, r, ql, qr);
    up(o);
  }
}
int query(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    return tr[o].mi;
  }
  int mid = l + r >> 1;
  down(o);
  int ret = 1e9;
  if (ql < mid) ret = min(ret, query(o << 1, l, mid, ql, qr));
  if (qr > mid) ret = min(ret, query(o << 1 | 1, mid, r, ql, qr));
  return ret;
}
int t[N], h[N], b[N + N], c[N * 3];
struct Duck {
  int h, t;
  bool operator<(const Duck &rhs) const { return t < rhs.t; }
} ducks[N];
map<int, int> id;
int main() {
  int n, k, m = 0, cnt = 0, j = 0, pb = 0, pc = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ducks[i].h, &ducks[i].t);
    ducks[i].h = max(ducks[i].h, 0);
    if (ducks[i].t < 0) {
      i--;
      n--;
      continue;
    }
    b[m++] = ducks[i].h;
    b[m++] = ducks[i].t + 1;
  }
  sort(b, b + m);
  m = unique(b, b + m) - b;
  b[m] = inf;
  sort(ducks, ducks + n);
  int cur = -inf, sz = n * 3 + 1, v;
  while (cur < inf) {
    while (j < n && ducks[j].t < cur) {
      update(1, 0, sz, 0, id[ducks[j].h]);
      j++;
    }
    c[cnt] = cur;
    id[cur] = cnt++;
    if (cnt > 1) {
      v = query(1, 0, sz, 0, id.upper_bound(cur - k)->second);
      setValue(1, 0, sz, cnt - 1, v);
    }
    while (pb < m && b[pb] <= cur) {
      pb++;
    }
    while (pc < cnt && c[pc] + k <= cur) {
      pc++;
    }
    cur = b[pb];
    while (pc < cnt && c[pc] + k < b[pb]) {
      if (pc && query(1, 0, sz, 0, pc) > query(1, 0, sz, pc, pc + 1)) {
        cur = c[pc] + k;
        break;
      } else
        pc++;
    }
  }
  printf("%d\n", n - query(1, 0, sz, 0, cnt));
  return 0;
}
