#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T>
bool chmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
vector<int> sol(vector<int> v) {
  int N = v.size();
  vector<int> ret(N + 1);
  vector<int> dp(N + 1, 1e9);
  dp[0] = 0;
  for (int i = (0), i_end_ = (N); i < i_end_; i++) {
    int t = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
    ret[i + 1] = max(ret[i], t);
    dp[t] = v[i];
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> imos(M + 1);
  while (N--) {
    int l, r;
    cin >> l >> r;
    imos[l - 1]++;
    imos[r]--;
  }
  for (int i = (0), i_end_ = (M); i < i_end_; i++) imos[i + 1] += imos[i];
  imos.pop_back();
  vector<int> v = sol(imos);
  reverse(imos.begin(), imos.end());
  vector<int> w = sol(imos);
  int ret = 0;
  for (int i = (0), i_end_ = (M + 1); i < i_end_; i++) {
    chmax(ret, v[i] + w[M - i]);
  }
  cout << ret << "\n";
}
