#include <bits/stdc++.h>
using namespace std;
int n, k;
priority_queue<pair<int, int> > q;
struct Segment_Tree {
  struct node {
    int mx, sum;
    int ch[2];
  } tr[5000100];
  int root;
  int tot;
  void newnode(int &x) {
    x = ++tot;
    tr[tot].mx = tr[tot].ch[0] = tr[tot].ch[1] = 0;
  }
  void update(int x) {
    tr[x].mx = tr[x].sum + max(tr[tr[x].ch[0]].mx, tr[tr[x].ch[1]].mx);
  }
  void change(int &x, int l, int r, int a, int b) {
    if (!x) newnode(x);
    if (l == r - 1) {
      tr[x].sum = tr[x].mx = b;
      return;
    }
    int mid = l + r >> 1;
    if (a < mid)
      change(tr[x].ch[0], l, mid, a, b);
    else
      change(tr[x].ch[1], mid, r, a, b);
    update(x);
  }
  void insert(int x, int l, int r, int a, int b) {
    if (!x || b <= l || a >= r) return;
    if (a <= l && r <= b) {
      tr[x].mx++;
      tr[x].sum++;
      return;
    }
    int mid = l + r >> 1;
    insert(tr[x].ch[0], l, mid, a, b);
    insert(tr[x].ch[1], mid, r, a, b);
    update(x);
  }
  int query(int x, int l, int r, int a, int b) {
    if (!x || b <= l || a >= r) return 0;
    if (a <= l && r <= b) return tr[x].mx;
    int mid = l + r >> 1;
    return tr[x].sum + max(query(tr[x].ch[0], l, mid, a, b),
                           query(tr[x].ch[1], mid, r, a, b));
  }
} sg;
int main() {
  int l, r, sum = 0;
  scanf("%d%d", &n, &k);
  sum = n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r);
    if (r < 0) continue;
    l = max(0, l);
    q.push(make_pair(-r, -l));
    q.push(make_pair(-l, 2));
  }
  int pre = -1;
  while (q.size()) {
    int l = -q.top().second, r = -q.top().first;
    q.pop();
    if (l < 0) {
      if (r == pre) continue;
      int v = sg.query(sg.root, 0, int(1e9), 0, r - k + 1);
      if (l == -2 || v > sg.query(sg.root, 0, int(1e9), pre, pre + 1)) {
        pre = r;
        sg.change(sg.root, 0, int(1e9), r, v);
        if (r + k <= int(1e9)) {
          q.push(make_pair(-r - k, 1));
        }
      }
    } else
      sg.insert(sg.root, 0, int(1e9), l, r + 1);
  }
  printf("%d\n", sg.tr[sg.root].mx);
  return 0;
}
