#include <bits/stdc++.h>
using namespace std;
int N, M;
pair<int, int> t[200005];
vector<int> G[200005];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    t[i] = pair<int, int>(l, r);
    G[l].push_back(i);
  }
  vector<int> z;
  for (int id : G[0]) z.push_back(id);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  int cnt = 0;
  for (int i = 1; i <= M + 1; i++) {
    for (int id : G[i]) {
      int r = t[id].second;
      if (min(i, M) - cnt > 0) {
        cnt++;
        Q.push(pair<int, int>(r, id));
      } else {
        Q.push(pair<int, int>(r, id));
        pair<int, int> p = Q.top();
        Q.pop();
        z.push_back(p.second);
      }
    }
  }
  for (int i = 0; i < 200005; i++) G[i].clear();
  for (int id : z) {
    G[t[id].second].push_back(id);
  }
  int cc = 0;
  for (int i = M; i >= 1; i--) {
    for (int id : G[i]) {
      if (M - i + 1 - cc > 0) {
        cc++;
      }
    }
  }
  cout << N - M + (M - cc - cnt) << endl;
  return 0;
}
