#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 55;
const double pi = acos(-1);
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T>
class Lazy_Segment_Tree {
 private:
  int n;
  vector<T> date, lazy;
  void Set_Lazy(int k, T x) {
    date[k] += x;
    lazy[k] += x;
  }
  void Push(int k) {
    Set_Lazy(k * 2 + 1, lazy[k]);
    Set_Lazy(k * 2 + 2, lazy[k]);
    lazy[k] = 0;
  }
  void Fix(int k) { date[k] = min(date[k * 2 + 1], date[k * 2 + 2]); }
  void Add_func(int a, int b, int k, int l, int r, T x) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      Set_Lazy(k, x);
      return;
    }
    Push(k);
    int m = (l + r) / 2;
    Add_func(a, b, k * 2 + 1, l, m, x);
    Add_func(a, b, k * 2 + 2, m, r, x);
    Fix(k);
  }

 public:
  Lazy_Segment_Tree(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    date = lazy = vector<T>(2 * n - 1);
    for (int i = 0; i < n_; i++) date[i + n - 1] = n_ - i - 1;
    for (int i = n - 2; i >= 0; i--)
      date[i] = min(date[i * 2 + 1], date[i * 2 + 2]);
  }
  void Add(int a, int b, T x) { Add_func(a, b, 0, 0, n, x); }
  T Min() { return date[0]; }
};
int n, m;
vector<vector<int> > a;
int main() {
  cin >> n >> m;
  a = vector<vector<int> >(m + 1);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    a[l].push_back(r);
  }
  Lazy_Segment_Tree<int> st(m + 1);
  priority_queue<int> q;
  int t = 0;
  for (int l = 0; l <= m; l++) {
    for (auto r : a[l]) {
      q.push(r);
      st.Add(0, r, -1);
      t++;
    }
    while (st.Min() < 0) {
      int r = q.top();
      st.Add(0, r, 1);
      t--;
    }
    st.Add(0, m + 1, 1);
  }
  cout << n - t << endl;
}
