#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << "," << v.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  long long sz = v.size();
  for (long long i = 0; i < sz; ++i) {
    os << v[i];
    if (i != sz - 1) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  T last = *v.rbegin();
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != last) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v) {
    os << it.first << " : " << it.second << "\n";
  }
  return os;
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long N = 1e5 + 5;
long long counts[N];
long long fen[N];
long long pref[N], suff[N];
long long get(long long i) {
  long long res = 0;
  while (i > 0) {
    res = max(res, fen[i]);
    i -= (i & (-i));
  }
  return res;
}
void upd(long long i, long long val) {
  while (i < N) {
    fen[i] = max(fen[i], val);
    i += (i & (-i));
  }
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    ++counts[l], --counts[r + 1];
  }
  for (long long i = 2; i <= m; ++i) {
    counts[i] += counts[i - 1];
  }
  set<long long> arr;
  for (long long i = 1; i <= m; ++i) arr.insert(counts[i]);
  long long idx = 0;
  map<long long, long long> indexing;
  for (auto it : arr) indexing[it] = ++idx;
  for (long long i = 1; i <= m; ++i) counts[i] = indexing[counts[i]];
  memset(fen, 0, sizeof(fen));
  for (long long i = 1; i <= m; ++i) {
    pref[i] = get(counts[i] + 1) + 1;
    upd(counts[i] + 1, pref[i]);
  }
  long long ans = 0;
  memset(fen, 0, sizeof(fen));
  for (long long i = m; i >= 1; --i) {
    suff[i] = get(counts[i] + 1) + 1;
    ans = max(ans, pref[i] + suff[i] - 1);
    upd(counts[i] + 1, suff[i]);
  }
  cout << ans << endl;
  return 0;
}
