#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
bool mrk[200000 + 5];
struct menber {
  int l, r;
} men[200000 + 5];
bool cmp(menber x, menber y) { return x.l < y.l; }
bool cmp2(int x, int y) { return men[x].r > men[y].r; }
priority_queue<int, vector<int>, greater<int> > pq;
priority_queue<int> miss;
int cnt = 1;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) men[i].l = read(), men[i].r = read();
  sort(men + 1, men + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (cnt <= men[i].l) {
      mrk[cnt++] = 1;
      if (men[i].r <= m) pq.push(men[i].r);
      continue;
    }
    if (cnt > men[i].l) {
      if (men[i].r <= m) pq.push(men[i].r);
      bool ok = 0;
      while (!pq.empty()) {
        if (!mrk[pq.top()]) {
          mrk[pq.top()] = 1, pq.pop();
          ok = 1;
          break;
        } else
          pq.pop();
      }
      if (!ok) miss.push(men[i].r);
    }
  }
  int ans = miss.size();
  if (ans == 0) {
    printf("0\n");
    return 0;
  }
  cnt = m;
  while (true) {
    while (cnt && mrk[cnt]) cnt--;
    while (!miss.empty() && miss.top() > cnt) miss.pop();
    if (miss.empty() || !cnt) break;
    mrk[cnt] = 1;
    miss.pop();
    ans--;
  }
  printf("%d\n", ans);
  return 0;
}
