#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, m, tot, ans;
int Max[maxn << 2], Add[maxn << 2], C[maxn];
struct seg {
  int l, r;
} a[maxn];
bool cmp(const seg& i, const seg& j) { return i.r < j.r; }
inline int lowbit(const int& x) { return x & (-x); }
void add(int x, int val) {
  for (int i = x; i < maxn; i += lowbit(i)) C[i] += val;
}
int sum(int x) {
  int ret = 0;
  for (int i = x; i; i -= lowbit(i)) ret += C[i];
  return ret;
}
void pushup(int rt) { Max[rt] = max(Max[(rt << 1)], Max[(rt << 1 | 1)]); }
void build(int rt, int l, int r) {
  if (l == r) {
    Max[rt] = l - 1;
    return;
  }
  int mid = l + r >> 1;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  pushup(rt);
}
void lazy(int rt, int val) {
  Max[rt] += val;
  Add[rt] += val;
}
void pushdown(int rt) {
  if (Add[rt]) {
    lazy((rt << 1), Add[rt]);
    lazy((rt << 1 | 1), Add[rt]);
    Add[rt] = 0;
  }
}
void update(int rt, int l, int r, int a, int b, int val) {
  if (a <= l && r <= b) {
    lazy(rt, val);
    return;
  }
  pushdown(rt);
  int mid = l + r >> 1;
  if (a <= mid) update((rt << 1), l, mid, a, b, val);
  if (b > mid) update((rt << 1 | 1), mid + 1, r, a, b, val);
  pushup(rt);
}
int query(int rt, int l, int r, int a, int b) {
  if (a <= l && r <= b) return Max[rt];
  pushdown(rt);
  int mid = l + r >> 1;
  int lMax = 0, rMax = 0;
  if (a <= mid) lMax = query((rt << 1), l, mid, a, b);
  if (b > mid) rMax = query((rt << 1 | 1), mid + 1, r, a, b);
  return max(lMax, rMax);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l == 0 && r == m + 1)
      ++ans;
    else {
      ++tot;
      a[tot].l = r;
      a[tot].r = l + m;
      if (a[tot].r <= m) {
        a[tot].l += m;
        a[tot].r += m;
      }
    }
  }
  sort(a + 1, a + tot + 1, cmp);
  build(1, 1, 2 * m);
  for (int i = 1; i <= 2 * m; ++i) add(i, 1);
  for (int i = 1; i <= tot; ++i) {
    update(1, 1, 2 * m, 1, a[i].l, 1);
    int ret = query(1, 1, 2 * m, a[i].r - m + 1, a[i].r);
    if (ret > sum(a[i].r)) {
      ++ans;
      add(a[i].r, 1);
      if (a[i].r + 1 <= 2 * m) update(1, 1, 2 * m, a[i].r + 1, 2 * m, 1);
    }
  }
  ans = max(ans, n - m);
  cout << ans << endl;
  return 0;
}
