#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  vector<vector<int>> el(m + 1);
  for (int i = 0; i < n; i++) {
    el[l[i]].push_back(i);
  }
  vector<int> usedp(n, false);
  vector<int> usedc(m + 1, false);
  priority_queue<pair<int, int>> que;
  for (int i = m; i > 0; i--) {
    for (auto e : el[i]) que.push(make_pair(r[e], e));
    if (!que.empty()) {
      auto tmp = que.top();
      usedp[tmp.second] = true;
      usedc[i] = true;
      que.pop();
    }
  }
  vector<int> rest;
  for (int i = 0; i < n; i++) {
    if (!usedp[i]) rest.push_back(i);
  }
  sort(rest.begin(), rest.end(),
       [&r](int lhs, int rhs) { return r[lhs] > r[rhs]; });
  ;
  int idx = m;
  for (auto e : rest) {
    while (idx > 0 && usedc[idx]) idx--;
    if (idx == 0) break;
    if (r[e] <= idx) {
      usedc[idx] = true;
    }
  }
  cout << n - accumulate(usedc.begin(), usedc.end(), 0) << endl;
  return 0;
}
