#include <bits/stdc++.h>
using namespace std;
int mval[1 << 21], add[1 << 21];
struct duck {
  int h, t;
  bool operator<(const duck& rhs) const {
    return t < rhs.t || t == rhs.t && h < rhs.h;
  }
} d[200100];
inline int qmin(int u) { return mval[u] + add[u]; }
inline void push(int u) {
  mval[u] += add[u];
  add[u << 1] += add[u];
  add[u << 1 | 1] += add[u];
  add[u] = 0;
}
inline void pull(int u) { mval[u] = min(qmin(u << 1), qmin(u << 1 | 1)); }
void upd(int u, int l, int r, int ql, int qr, int v) {
  if (ql >= qr) return;
  if (l == ql && r == qr) {
    add[u] += v;
    return;
  }
  int m = (l + r) / 2;
  push(u);
  if (qr <= m)
    upd(u << 1, l, m, ql, qr, v);
  else if (ql >= m)
    upd(u << 1 | 1, m, r, ql, qr, v);
  else {
    upd(u << 1, l, m, ql, m, v);
    upd(u << 1 | 1, m, r, m, qr, v);
  }
  pull(u);
}
int qry(int u, int l, int r, int ql, int qr) {
  if (ql >= qr) return 1023456789;
  if (l == ql && r == qr) {
    return qmin(u);
  }
  int m = (l + r) / 2;
  push(u);
  if (qr <= m)
    return qry(u << 1, l, m, ql, qr);
  else if (ql >= m)
    return qry(u << 1 | 1, m, r, ql, qr);
  else
    return min(qry(u << 1, l, m, ql, m), qry(u << 1 | 1, m, r, m, qr));
}
int main() {
  map<int, int> id;
  set<int> head;
  int n, r, pt = -1023456789 - 1, cnt = 0, sz, j = 0, nv = 0, pv = 0;
  priority_queue<int, deque<int>, greater<int> > pq;
  pq.push(-1023456789);
  scanf("%d%d", &n, &r);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &d[i].h, &d[i].t);
    if (d[i].t < 0) {
      i--;
      n--;
      continue;
    }
    if (d[i].h < 0) d[i].h = 0;
    pq.push(d[i].h);
    pq.push(d[i].t + 1);
    head.insert(d[i].h);
  }
  sort(d, d + n);
  sz = n * 4 + 1;
  while (!pq.empty()) {
    int nt = pq.top();
    pq.pop();
    if (nt == pt) continue;
    while (j < n && d[j].t < nt) {
      upd(1, 0, sz, 0, id[d[j].h], 1);
      j++;
    }
    id[nt] = cnt++;
    if (cnt > 1) {
      nv = qry(1, 0, sz, 0, id.upper_bound(nt - r)->second);
      pv = qry(1, 0, sz, cnt - 2, cnt - 1);
      upd(1, 0, sz, cnt - 1, sz, nv - pv);
    }
    if (head.count(nt) || nv < pv) pq.push(nt + r);
    pt = nt;
  }
  while (j < n) {
    upd(1, 0, sz, 0, id[d[j].h], 1);
    j++;
  }
  printf("%d\n", n - qmin(1));
  return 0;
}
