#include <bits/stdc++.h>
using namespace std;
struct aa {
  int l, r;
} a[200010];
int n, m, i, ans, now;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline bool cmp(aa a, aa b) {
  if (a.l == b.l) return a.r > b.r;
  return a.l < b.l;
}
struct heap {
  struct bb {
    int val;
  } a[200010];
  int cnt;
  inline bool check(int x, int y) { return a[x].val < a[y].val; }
  inline void up(int x) {
    int k = x / 2;
    while (k) {
      if (check(x, k))
        swap(a[x], a[k]);
      else
        return;
      x = k;
      k = x / 2;
    }
  }
  inline void down(int x) {
    int k = x * 2;
    while (k <= cnt) {
      if (k + 1 <= cnt && check(k, k + 1)) k++;
      if (check(k, x))
        swap(a[x], a[k]);
      else
        return;
      x = k;
      k = x * 2;
    }
  }
  inline void pop() {
    swap(a[1], a[cnt]);
    cnt--;
    down(1);
  }
  inline void insert(int y) {
    cnt++;
    a[cnt].val = y;
    up(cnt);
  }
} Heap;
int main() {
  n = read();
  m = read();
  for (i = 1; i <= n; i++) {
    a[i].l = read();
    a[i].r = read();
  }
  sort(a + 1, a + n + 1, cmp);
  for (now = 1; now <= n; now++)
    if (a[now].l) break;
  now--;
  for (i = 1; i <= now; i++) Heap.insert(a[1].r);
  for (i = 1; i <= m; i++) {
    while (now < n && a[now + 1].l < i) now++, Heap.insert(a[now].r);
    if (now < n) {
      now++;
      ans++;
      if (ans == n) break;
      continue;
    }
    if (Heap.cnt && Heap.a[1].val <= i) {
      Heap.pop();
      ans++;
      if (ans == n) break;
      continue;
    }
  }
  write(n - ans);
}
