#include <bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
  char ch;
  bool flag = false;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') flag = true;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  x = flag ? -x : x;
}
inline void write(long long x) {
  static const long long maxlen = 100;
  static char s[maxlen];
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  long long len = 0;
  for (; x; x /= 10) s[len++] = x % 10 + '0';
  for (long long i = len - 1; i >= 0; --i) putchar(s[i]);
}
inline void read(int &x) {
  char ch;
  bool flag = false;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') flag = true;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  x = flag ? -x : x;
}
const long long MAXN = 310000;
int n, m;
struct kt {
  int l, r;
} a[MAXN];
bool cmp_l(kt A, kt B) {
  if (A.l != B.l) return A.l < B.l;
  return A.r < B.r;
}
int tree[MAXN * 7];
int query_ans(int p, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  if (tree[p * 2 + 1] < (r - (mid + 1) + 1))
    return query_ans(p * 2 + 1, mid + 1, r);
  return query_ans(p * 2, l, mid);
}
int query_r(int p, int l, int r, int a, int b) {
  if ((l == a) && (r == b)) {
    if (tree[p] == (r - l + 1)) return -1;
    return query_ans(p, l, r);
  }
  int mid = (l + r) / 2;
  if (b <= mid)
    return query_r(p * 2, l, mid, a, b);
  else if (a > mid)
    return query_r(p * 2 + 1, mid + 1, r, a, b);
  else {
    int tmp = query_r(p * 2 + 1, mid + 1, r, mid + 1, b);
    if (tmp != -1) return tmp;
    return query_r(p * 2, l, mid, a, mid);
  }
}
void add(int p, int l, int r, int x) {
  tree[p]++;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (x <= mid)
    add(p * 2, l, mid, x);
  else
    add(p * 2 + 1, mid + 1, r, x);
}
int main() {
  read(n);
  read(m);
  int cnt = 0;
  int cnt_all = 0;
  for (int i = 1; i <= n; i++) {
    int x, y;
    read(x);
    read(y);
    if (x == y - 1) {
      cnt_all++;
      continue;
    }
    ++cnt;
    a[cnt].l = x;
    a[cnt].r = y;
  }
  sort(a + 1, a + cnt + 1, cmp_l);
  int ans = 0;
  int pre = 0;
  int l_tot = 0;
  for (int i = 1; i <= cnt; i++)
    if (pre < a[i].l) {
      pre++;
      l_tot++;
      ans++;
    }
  for (int i = 1; i <= cnt - l_tot; i++) {
    a[i].r = max(a[i].r, l_tot + 1);
    if (a[i].r > m) continue;
    int pos = query_r(1, 1, m, 1, m - a[i].r + 1);
    if (pos != -1) {
      add(1, 1, m, pos);
      ans++;
    }
  }
  ans = min(m, ans + cnt_all);
  cout << n - ans << endl;
  return 0;
}
