#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = {0, 1, 0, -1};
constexpr int dw[4] = {-1, 0, 1, 0};
bool isin(const int H, const int W, const int h, const int w) {
  return 0 <= h && h < H && 0 <= w && w < W;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pii> lr(N);
  for (int((i)) = (0); ((i)) < ((N)); ((i))++) {
    int l, r;
    cin >> l >> r;
    lr[i] = {l, -r};
  }
  sort(lr.begin(), lr.end());
  set<int> chair;
  vector<pii> stands;
  for (int(i) = (1); (i) < (M + 1); (i)++) chair.insert(i);
  for (auto p : lr) {
    int l = p.first;
    auto itr = chair.upper_bound(l);
    if (itr == chair.begin()) {
      stands.push_back({-p.second, p.first});
    } else {
      --itr;
      chair.erase(itr);
    }
  }
  sort(stands.begin(), stands.end());
  int shortage = 0;
  for (auto stand : stands) {
    int r = stand.first;
    auto itr = chair.lower_bound(r);
    if (itr == chair.end()) {
      shortage++;
    } else {
      chair.erase(itr);
    }
  }
  cout << shortage << endl;
  return 0;
}
