#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());
  long long ans = 0, r = (1LL << 60);
  for (long long i = (0); i < ((n)); ++i) {
    chmin(r, a[i].second);
    if (a[i].first < r)
      chmax(ans, i + 1 - (a[i].first + m - r + 1));
    else
      chmax(ans, n - m);
  }
  cout << ans << endl;
  return 0;
}
