#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, K, tr[6000010], tag[6000010], lc[6000010], rc[6000010], rt, x = 0,
                                                                   lst = -1;
priority_queue<pair<int, int> > q;
void pushup(int t) { tr[t] = max(tr[lc[t]], tr[rc[t]]) + tag[t]; }
void upd(int a, int l, int r, int &t, int c) {
  if (!t) t = ++x;
  if (l == r) return tag[t] = tr[t] = c, void();
  int mid = (l + r) >> 1;
  if (a <= mid)
    upd(a, l, mid, lc[t], c);
  else
    upd(a, mid + 1, r, rc[t], c);
  pushup(t);
}
void add(int ll, int rr, int l, int r, int t) {
  if (!t) return;
  if (ll <= l && r <= rr) return tr[t]++, tag[t]++, void();
  int mid = (l + r) >> 1;
  if (ll <= mid) add(ll, rr, l, mid, lc[t]);
  if (mid < rr) add(ll, rr, mid + 1, r, rc[t]);
  pushup(t);
}
int qry(int ll, int rr, int l, int r, int t) {
  if (!t) return 0;
  if (ll <= l && r <= rr) return tr[t];
  int mid = (l + r) >> 1;
  if (rr <= mid) return qry(ll, rr, l, mid, lc[t]) + tag[t];
  if (mid < ll) return qry(ll, rr, mid + 1, r, rc[t]) + tag[t];
  return max(qry(ll, rr, l, mid, lc[t]), qry(ll, rr, mid + 1, r, rc[t])) +
         tag[t];
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1, s, t; i <= n; i++) {
    scanf("%d%d", &s, &t);
    if (t < 0) continue;
    s = max(0, s);
    q.push(make_pair((-t), (-s))), q.push(make_pair((-s), (1)));
  }
  while (q.size()) {
    int l = -q.top().second, r = -q.top().first;
    q.pop();
    if (l >= 0) {
      add(l, r, 0, inf, rt);
      continue;
    }
    if (r == lst) continue;
    int u = lst >= 0 ? qry(lst, lst, 0, inf, rt) : 0,
        v = r - K >= 0 ? qry(0, r - K, 0, inf, rt) : 0;
    if (l == -1 || u < v) {
      lst = r;
      upd(r, 0, inf, rt, v);
      if (r + K <= inf) q.push(make_pair((-r - K), (2)));
    }
  }
  printf("%d\n", tr[rt]);
}
