#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using lim = numeric_limits<T>;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
  for (T& x : a) {
    is >> x;
  }
  return is;
}
template <typename X, typename Y>
istream& operator>>(istream& is, pair<X, Y>& p) {
  return is >> p.first >> p.second;
}
void solve(long long N, long long M, std::vector<long long> L,
           std::vector<long long> R) {
  vector<vector<int>> opens_at(M + 2), closes_at(M + 2);
  for (int i = 0; i < N; i++) {
    closes_at[L[i]].push_back(i);
    opens_at[R[i]].push_back(i);
  }
  auto ordering = [&](int i) {
    return make_tuple(L[i] == 0 ? M + 1 : L[i], -R[i], i);
  };
  auto cmp = [&](int i, int j) { return ordering(i) < ordering(j); };
  set<int, decltype(cmp)> s(cmp);
  for (int i = 0; i < N; i++) {
    s.insert(i);
  }
  vector<bool> seated(N);
  for (int x = 0; x <= M + 1; x++) {
    for (int i : opens_at[x]) {
      if (not seated[i]) {
        s.insert(i);
      }
    }
    if (1 <= x and x <= M) {
      if (not s.empty()) {
        seated[*s.begin()] = true;
        s.erase(s.begin());
      }
    }
    for (int i : closes_at[x]) {
      s.erase(i);
    }
  }
  cout << N - count(seated.begin(), seated.end(), true) << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> L(N);
  std::vector<long long> R(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve(N, M, std::move(L), std::move(R));
  return 0;
}
