#include <bits/stdc++.h>
using namespace std;
template <typename Type>
class RMQ {
 private:
  unsigned size_;
  std::vector<Type> dat;
  inline Type query_(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return make_pair(1 << 30, 1 << 30);
    if (a <= l && r <= b) return dat[k];
    Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
    Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
    return std::min(lc, rc);
  }

 public:
  RMQ() : size_(0), dat(std::vector<Type>()){};
  RMQ(int size__) {
    for (size_ = 1; size_ < size__;) size_ <<= 1;
    dat.resize(size_ << 1, make_pair(1 << 30, 1 << 30));
  }
  template <class T>
  RMQ(T begin_, T end_) {
    int n = end_ - begin_;
    for (size_ = 1; size_ < n; size_ <<= 1)
      ;
    dat.resize(size_ << 1, make_pair(1 << 30, 1 << 30));
    for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
    for (int i = size_ - 1; i > 0; i--)
      dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
  }
  inline unsigned size() { return size_; }
  inline void update(int i, Type x) {
    i += size_;
    dat[i] = x;
    while (i > 1) {
      i >>= 1;
      dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
    }
  }
  inline Type query(int l, int r) { return query_(l, r, 1, 0, size_); }
};
int n, m, l[400000], r[400000], cnt;
vector<pair<int, int>> E;
vector<int> F;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    r[i] = m + 1 - r[i];
    E.push_back(make_pair(l[i], r[i]));
  }
  sort(E.begin(), E.end());
  RMQ<pair<int, int>> X(n + 1);
  for (int i = 0; i < n; i++) X.update(i, make_pair(r[i], i));
  X.update(n, make_pair(1 << 30, n));
  for (int i = m; i >= 1; i--) {
    int pos1 = lower_bound(E.begin(), E.end(), make_pair(i, 0)) - E.begin();
    pair<int, int> R = X.query(pos1, n + 1);
    if (R.first < 1e9) {
      X.update(R.second, make_pair(1 << 30, R.second));
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (X.query(i, i + 1).first < 1e9) F.push_back(r[i]);
  }
  int T = 1;
  sort(F.begin(), F.end());
  for (int i = 0; i < F.size(); i++) {
    if (F[i] >= T) {
      cnt++;
      T++;
    }
  }
  cout << n - cnt << endl;
  return 0;
}
