#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> a(n);
  for (long long i = (0); i < ((n)); ++i) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  priority_queue<long long, vector<long long>, greater<long long>> que;
  vector<long long> b;
  long long mx = 0;
  for (long long i = (0); i < ((n)); ++i) {
    que.push(a[i].second);
    if (a[i].first >= mx + 1)
      mx++;
    else
      b.push_back(que.top()), que.pop();
  }
  sort(b.rbegin(), b.rend());
  long long mx2 = 0;
  for (long long i = (0); i < ((b.size())); ++i)
    if (b[i] <= m - mx2) mx2++;
  cout << n - mx - mx2 << endl;
  return 0;
}
