#include <bits/stdc++.h>
using std::greater;
using std::priority_queue;
using std::vector;
const int N = 2e5 + 10;
struct Node {
  int l, r;
  bool operator<(const Node &A) const { return r < A.r; }
  bool operator>(const Node &A) const { return r > A.r; }
} p[N];
int n, m;
void Init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].l, &p[i].r);
}
bool cmpl(const Node &A, const Node &B) {
  return A.l < B.l || (A.l == B.l && A.r < B.r);
}
priority_queue<Node, vector<Node>, greater<Node> > Q, T;
void Solve() {
  std::sort(p + 1, p + n + 1, cmpl);
  int t = 1, inq = 0, cant = 0;
  while (p[t].l == 0 && t <= n) T.push(p[t]), ++t;
  for (int i = 1; i <= m; ++i) {
    while (p[t].l == i && t <= n) {
      if (inq < i) {
        inq++;
        Q.push(p[t]);
      } else {
        Q.push(p[t]);
        T.push(Q.top());
        Q.pop();
      }
      ++t;
    }
    while (inq < i - cant && !T.empty()) {
      Node w = T.top();
      if (w.r > i) {
        cant = i - inq;
        break;
      }
      inq++, Q.push(T.top()), T.pop();
    }
  }
  printf("%d\n", n - inq);
}
int main() {
  Init();
  Solve();
  return 0;
}
