#include <bits/stdc++.h>
using namespace std;
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
  return A;
}
int main() {
  ios::sync_with_stdio(false);
  int N = getint();
  int M = getint();
  vector<pair<int, int> > V[200002];
  vector<int> V2[200002];
  bool usedM[200001] = {};
  bool usedN[200001] = {};
  int kazu = 0;
  for (int i = 0; i < (N); i++) {
    int l = getint();
    int r = getint();
    if (l + 1 != r) {
      V[l].push_back(make_pair(r, i));
      V2[r].push_back(i);
    } else
      kazu++;
  }
  priority_queue<pair<int, int> > PQ;
  int kotae = N;
  for (int i = M; i >= 1; i--) {
    for (auto p : V[i]) PQ.push(p);
    if (!PQ.empty()) {
      kotae--;
      auto p = PQ.top();
      PQ.pop();
      usedN[p.second] = true;
      usedM[i] = true;
    }
  }
  for (int i = 1; i <= (M); i++) {
    for (int j : V2[i])
      if (!usedN[j]) kazu++;
    if (kazu > 0 && !usedM[i]) {
      kotae--;
      kazu--;
    }
  }
  cout << (kotae) << "\n";
  return 0;
}
