#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;
}
vector<int> v[200000 + 5];
int n, l[200000 + 5], b[200000 + 5], r[200000 + 5], ans = 0, m;
priority_queue<int> q;
inline void Move(int& R) {
  for (; R && b[R]; --R)
    ;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i)
    l[i] = read(), r[i] = read(), v[l[i]].push_back(i);
  for (int i = m; ~i; --i) {
    for (int j = 0; j < v[i].size(); ++j) q.push(r[v[i][j]]);
    if (i && q.size()) q.pop(), ++ans, b[i] = 1;
  }
  int R = m;
  Move(R);
  while (q.size()) {
    if (q.top() <= R) b[R] = 1, Move(R), ++ans;
    q.pop();
  }
  cout << n - ans;
  return 0;
}
