#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct Segtree {
  int l, r;
  int mx, lazy;
} tr[N * 16];
void build(int id, int l, int r) {
  tr[id].l = l;
  tr[id].r = r;
  tr[id].mx = tr[id].lazy = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build((id << 1), l, mid);
  build((id << 1 | 1), mid + 1, r);
}
inline void push_up(int id) {
  tr[id].mx = max(tr[(id << 1)].mx, tr[(id << 1 | 1)].mx);
}
inline void push_down(int id) {
  if (!tr[id].lazy) return;
  tr[(id << 1)].lazy += tr[id].lazy;
  tr[(id << 1 | 1)].lazy += tr[id].lazy;
  tr[(id << 1)].mx += tr[id].lazy;
  tr[(id << 1 | 1)].mx += tr[id].lazy;
  tr[id].lazy = 0;
}
void update(int id, int l, int r, int v) {
  if (tr[id].l == l && tr[id].r == r) {
    tr[id].mx += v;
    tr[id].lazy += v;
    return;
  }
  push_down(id);
  int mid = (tr[id].l + tr[id].r) >> 1;
  if (r <= mid)
    update((id << 1), l, r, v);
  else if (l > mid)
    update((id << 1 | 1), l, r, v);
  else {
    update((id << 1), l, mid, v);
    update((id << 1 | 1), mid + 1, r, v);
  }
  push_up(id);
}
int query(int id, int l, int r) {
  if (tr[id].l == l && tr[id].r == r) return tr[id].mx;
  push_down(id);
  int mid = (tr[id].l + tr[id].r) >> 1;
  if (r <= mid) return query((id << 1), l, r);
  if (l > mid) return query((id << 1 | 1), l, r);
  return max(query((id << 1), l, mid), query((id << 1 | 1), mid + 1, r));
}
int Inter[100], tc;
void get_int(int id, int l, int r) {
  if (tr[id].l == l && tr[id].r == r) {
    Inter[tc++] = id;
    return;
  }
  push_down(id);
  int mid = (tr[id].l + tr[id].r) >> 1;
  if (r <= mid)
    get_int((id << 1), l, r);
  else if (l > mid)
    get_int((id << 1 | 1), l, r);
  else {
    get_int((id << 1), l, mid);
    get_int((id << 1 | 1), mid + 1, r);
  }
}
map<int, int> mp;
int T, idx, pos[N * 4];
inline void add(int v) {
  mp[v] = ++idx;
  pos[idx] = v;
}
void solve(int id, int v, int lim) {
  if (tr[id].l == tr[id].r) {
    int x = pos[tr[id].l] + T;
    if (x >= lim) return;
    add(x);
    update(1, idx, idx, tr[id].mx);
    return;
  }
  push_down(id);
  if (tr[(id << 1)].mx > v) solve((id << 1), v, lim);
  v = max(v, tr[(id << 1)].mx);
  if (tr[(id << 1 | 1)].mx > v) solve((id << 1 | 1), v, lim);
}
int data[N * 3], cc;
pair<int, int> p[N];
int main() {
  int n, m = 0;
  scanf("%d%d", &n, &T);
  for (int i = 0; i < n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (r < 0) continue;
    l = max(l, 0);
    p[m++] = make_pair(r + 1, l);
    data[cc++] = r + 1;
    data[cc++] = r;
    data[cc++] = l;
  }
  data[cc++] = 0x3f3f3f3f;
  sort(p, p + m);
  sort(data, data + cc);
  cc = unique(data, data + cc) - data;
  build(1, 1, 4 * n);
  idx = 0;
  for (int i = 0, j = 0; i < cc; ++i) {
    add(data[i]);
    for (; j < m && p[j].first <= data[i]; ++j) {
      update(1, mp[p[j].second], mp[p[j].first - 1], 1);
    }
    map<int, int>::iterator it = mp.upper_bound(data[i] - T);
    int v = 0;
    if (it != mp.begin()) {
      v = query(1, 1, (--it)->second);
      update(1, idx, idx, v);
      ++it;
    }
    if (i == cc - 1 || data[i] + 1 == data[i + 1] || it->second == idx)
      continue;
    tc = 0;
    get_int(1, it->second, idx - 1);
    for (int k = 0; k < tc; ++k) {
      int x = Inter[k];
      if (pos[tr[x].l] + T >= data[i + 1]) break;
      if (tr[x].mx <= v) continue;
      solve(x, v, data[i + 1]);
      v = tr[x].mx;
    }
  }
  printf("%d\n", tr[1].mx);
  return 0;
}
