#include <bits/stdc++.h>
using namespace std;
const int MAXN = 220000;
struct People {
  int l, r;
  bool operator<(const People& rhs) const {
    return r < rhs.r || r == rhs.r && l > rhs.l;
  }
} a[MAXN];
struct SegmentTree {
  struct Node {
    int l, r, val;
  } tr[8 * MAXN];
  void build(int x, int l, int r) {
    tr[x].l = l;
    tr[x].r = r;
    tr[x].val = 0;
    if (l == r) return;
    int mid = l + r >> 1;
    build((x << 1), l, mid);
    build((x << 1 | 1), mid + 1, r);
  }
  void update(int x, int p) {
    tr[x].val++;
    if (tr[x].l == tr[x].r) return;
    int mid = tr[x].l + tr[x].r >> 1;
    if (p <= mid)
      update((x << 1), p);
    else
      update((x << 1 | 1), p);
  }
  int find(int x) {
    if (tr[x].l == tr[x].r) return tr[x].l;
    if (tr[(x << 1)].val < tr[(x << 1)].r - tr[(x << 1)].l + 1)
      return find((x << 1));
    else
      return find((x << 1 | 1));
  }
  int query(int x, int l, int r) {
    if (tr[x].l > r || tr[x].r < l) return r + 1;
    if (l <= tr[x].l && tr[x].r <= r)
      return tr[x].val < tr[x].r - tr[x].l + 1 ? find(x) : r + 1;
    return min(query((x << 1), l, r), query((x << 1 | 1), l, r));
  }
} st;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].r, &a[i].l), a[i].r += m;
  sort(a + 1, a + n + 1);
  int ans1 = 0, ans2 = 0;
  st.build(1, 1, 2 * m);
  for (int i = 1; i <= n; i++) {
    int p = st.query(1, a[i].l, a[i].r);
    if (p == a[i].r + 1)
      ans1++;
    else
      st.update(1, p);
  }
  st.build(1, 1, 2 * m);
  for (int i = 1; i <= n; i++) {
    int p = st.query(1, a[i].l, a[i].r);
    if (p == a[i].r + 1)
      ans2++;
    else {
      st.update(1, p);
      if (p - m >= 1) st.update(1, p - m);
      if (p + m <= 2 * m) st.update(1, p + m);
    }
  }
  printf("%d\n", max(ans1, ans2));
  return 0;
}
