#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
vector<long long> _l[((long long)401 * 1000)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    if (l == 0 && r == m + 1) {
      ans++;
      continue;
    }
    _l[l].push_back(r);
  }
  multiset<long long> s;
  long long xr = m, rem = 0;
  for (long long xl = 0; xl <= m; xl++) {
    for (auto u : _l[xl]) {
      if (rem)
        s.insert(u), rem--;
      else {
        if (xr <= xl) {
          ans++;
          continue;
        }
        s.insert(u);
        auto it = s.upper_bound(xr);
        if (it == s.begin())
          ans++;
        else {
          xr--;
          it--;
          s.erase(it);
        }
      }
    }
    if (xr > xl) rem++;
  }
  cout << ans << "\n";
  return 0;
}
