#include <bits/stdc++.h>
using namespace std;
long long pp = 1000000007;
long long mo(long long a) {
  if (a >= 0 && a < pp) return a;
  a %= pp;
  if (a < 0) a += pp;
  return a;
}
long long powmod(long long a, long long b, long long pp) {
  long long ans = 1;
  for (; b; b >>= 1, a = mo(a * a))
    if (b & 1) ans = mo(ans * a);
  return ans;
}
long long read() {
  long long ans = 0;
  char last = ' ', ch = getchar();
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
int lson[10000000], rson[10000000], Max[10000000], sum[10000000], n, k, num,
    root;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q;
void build(int &u, int l, int r, int x, int y) {
  if (!u) u = ++num;
  if (l == r) {
    Max[u] = sum[u] = y;
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid)
    build(lson[u], l, mid, x, y);
  else
    build(rson[u], mid + 1, r, x, y);
  Max[u] = sum[u] + max(Max[lson[u]], Max[rson[u]]);
}
void add(int u, int l, int r, int x, int y) {
  if (!u || x > r || y < l) return;
  if (x <= l && y >= r) {
    sum[u]++;
    Max[u]++;
    return;
  }
  int mid = (l + r) / 2;
  add(lson[u], l, mid, x, y);
  add(rson[u], mid + 1, r, x, y);
  Max[u] = sum[u] + max(Max[lson[u]], Max[rson[u]]);
}
int get(int u, int l, int r, int x, int y) {
  if (!u || x > r || y < l) return 0;
  if (x <= l && y >= r) return Max[u];
  int mid = (l + r) / 2;
  return sum[u] +
         max(get(lson[u], l, mid, x, y), get(rson[u], mid + 1, r, x, y));
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    int l = read(), r = read();
    if (r < 0) continue;
    l = max(l, 0);
    Q.push(make_pair(r, l));
    Q.push(make_pair(l, -2));
  }
  int pre = -1;
  while (!Q.empty()) {
    pair<int, int> u = Q.top();
    Q.pop();
    if (u.second < 0) {
      if (u.first == pre) continue;
      int v = get(root, 0, 1000000000, 0, u.first - k);
      if (u.second == -2 || v > get(root, 0, 1000000000, pre, pre)) {
        build(root, 0, 1000000000, u.first, v);
        pre = u.first;
        if (u.first + k <= 1000000000) Q.push(make_pair(u.first + k, -1));
      }
    } else {
      add(root, 0, 1000000000, u.second, u.first);
    }
  }
  cout << Max[root] << endl;
  return 0;
}
