#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toll(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int cnt[(100000 + 3)], LISup[(100000 + 3)], LISdown[(100000 + 3)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    cnt[l - 1]++;
    cnt[r]--;
  }
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  multiset<int> muls;
  for (int i = 0; i < m; i++) {
    muls.insert(cnt[i]);
    auto it = muls.upper_bound(cnt[i]);
    if (it != muls.end()) muls.erase(it);
    LISup[i] = (int)muls.size();
  }
  muls.clear();
  for (int i = m - 1; i >= 0; i--) {
    muls.insert(cnt[i]);
    auto it = muls.upper_bound(cnt[i]);
    if (it != muls.end()) muls.erase(it);
    LISdown[i] = (int)muls.size();
  }
  int ans = 0;
  for (int i = 0; i < m; i++) ans = max(ans, LISup[i] + LISdown[i] - 1);
  cout << ans << endl;
  return 0;
}
