#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> vec(m + 2);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    vec[l]++, vec[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    vec[i] += vec[i - 1];
  }
  vector<int> st, f(m + 1);
  for (int i = 1; i <= m; i++) {
    if (st.empty() || vec[i] >= st.back()) {
      st.push_back(vec[i]);
    } else {
      *upper_bound(st.begin(), st.end(), vec[i]) = vec[i];
    }
    f[i] = st.size();
  }
  st.clear();
  int ans = f[m];
  for (int i = m; i >= 1; i--) {
    if (st.empty() || vec[i] >= st.back()) {
      st.push_back(vec[i]);
    } else {
      *upper_bound(st.begin(), st.end(), vec[i]) = vec[i];
    }
    ans = max(ans, f[i - 1] + (int)st.size());
  }
  cout << ans << endl;
  return 0;
}
