#include <bits/stdc++.h>
using namespace std;
struct query {
  long long l, r;
};
bool operator<(const query& a, const query& b) {
  if (a.l == b.l) {
    return a.r > b.r;
  } else
    return a.l < b.l;
}
long long n, m;
query qs[211111];
bool used[211111];
set<long long> ch, ch2;
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long a, b;
    cin >> a >> b;
    qs[i] = (query){a, b};
  }
  sort(qs, qs + n);
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    ch.insert(-(i + 1));
    ch2.insert(i + 1);
  }
  long long res = n;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long ql = qs[i].l;
    if (ql == 0) continue;
    auto tmp = ch.lower_bound(-ql);
    if (tmp == ch.end()) continue;
    if (-(*tmp) <= ql) {
      used[i] = true;
      res--;
      ch.erase(tmp);
      ch2.erase(-(*tmp));
    }
  }
  vector<long long> qrs;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long qr = qs[i].r;
    if (used[i] || qr == m + 1) continue;
    qrs.push_back(qr);
  }
  sort((qrs).begin(), (qrs).end(), greater<long long>());
  for (long long qr : qrs) {
    auto tmp = ch2.lower_bound(qr);
    if (tmp == ch2.end()) continue;
    if (qr <= *tmp) {
      res--;
      ch2.erase(*tmp);
    }
  }
  cout << res << endl;
  return 0;
}
