#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(m + 1);
  for (long long i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    l--;
    a[l]++;
    a[r]--;
  }
  for (long long i = 0, c = 0; i < m; ++i) {
    c += a[i];
    a[i] = c;
  }
  vector<long long> t(m + 2, 1e9);
  t[0] = -1e9;
  vector<long long> dp(m + 1);
  for (long long i = m - 1; i >= 0; --i) {
    long long idx = upper_bound(t.begin(), t.end(), a[i]) - t.begin();
    dp[i] = idx;
    t[idx] = a[i];
  }
  long long ans = dp[0];
  t = vector<long long>(m + 2, 1e9);
  t[0] = -1e9;
  for (long long i = 0; i < m; ++i) {
    long long idx = upper_bound(t.begin(), t.end(), a[i]) - t.begin();
    ans = max(ans, idx + dp[i + 1]);
    t[idx] = a[i];
  }
  cout << ans << '\n';
}
