#include <bits/stdc++.h>
using namespace std;
int l[200009], r[200009];
vector<int> v[200009];
int ult[200009];
int unde[200009], cine[200009];
struct lex_compare {
  bool operator()(const int &x, const int &y) const { return r[x] > r[y]; }
};
multiset<int, lex_compare> s;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
  for (int i = 0; i < n; i++) v[l[i]].push_back(i);
  for (int i = m; i > 0; i--) {
    for (auto &x : v[i]) s.insert(x);
    if (!s.empty()) {
      int x = *(s.begin());
      s.erase(s.begin());
      cine[i] = x;
      unde[x] = i;
    }
  }
  int rest = 0;
  for (int i = 1; i <= m; i++) {
    if (cine[i]) {
      int x = cine[i];
      cine[i] = 0;
      unde[x] = i - rest;
      cine[unde[x]] = x;
    } else
      rest++;
  }
  int q = 0;
  for (int i = 1; i <= n; i++)
    if (unde[i] == 0) ult[++q] = r[i];
  std::sort(ult + 1, ult + q + 1);
  int poz = 1;
  for (int i = 1; i <= m; i++)
    if (poz <= q && ult[poz] <= i) poz++;
  int ans = q - poz + 1;
  cout << ans;
  return 0;
}
