#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<tuple<int, int> > V;
int main() {
  cin >> N >> M;
  for (auto i = 0; i < N; ++i) {
    int L, R;
    cin >> L >> R;
    V.push_back(tuple<int, int>(L, -R));
  }
  sort(V.begin(), V.end());
  priority_queue<int, vector<int>, greater<int> > Q;
  vector<int> W;
  int ind = 1;
  for (auto x : V) {
    Q.push(-get<1>(x));
    if (ind <= get<0>(x)) {
      ++ind;
    } else {
      W.push_back(Q.top());
      Q.pop();
    }
  }
  for (auto it = W.begin(); it != W.end(); ++it) {
    *it = M + 1 - *it;
  }
  sort(W.begin(), W.end());
  ind = 1;
  int ans = 0;
  for (auto x : W) {
    if (ind <= x) {
      ++ind;
    } else {
      ++ans;
    }
  }
  cout << ans << endl;
}
