#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
namespace {
namespace aimi {
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = begin(x); i != end(x); _W(*i++))
    if (i != cbegin(x)) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
template <class T>
inline T get_bit(T x, int i) {
  return (x >> i) & 1;
}
template <class T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
struct BIT {
  int n;
  vector<T> dat;
  void init(int _n) {
    n = _n;
    dat.clear();
    dat.resize(n + 1);
  }
  void add(int x, T v) {
    for (int i = x; i <= n; i += i & -i) dat[i] = dat[i] + v;
  }
  T ask(int x) {
    T s = T();
    for (int i = x; i; i -= i & -i) s = s + dat[i];
    return s;
  }
};
constexpr int lg2(int x) { return 31 - __builtin_clz(x); }
const int N_MAX = 100005;
int n_seg, n;
int st[N_MAX], ed[N_MAX];
int diff[N_MAX];
int cov[N_MAX];
struct Max {
  int x;
  Max(int _x = 0) : x(_x) {}
  Max operator+(const Max &other) { return {max(x, other.x)}; }
};
BIT<Max> bit;
int ans_l[N_MAX], ans_r[N_MAX];
void main() {
  R(n_seg, n);
  for (int i = 0; i < int(n_seg); i++) {
    R(st[i], ed[i]);
    ++diff[st[i]];
    --diff[ed[i] + 1];
  }
  vector<PII> ord;
  for (int i = 1; i <= n; ++i) {
    cov[i] = cov[i - 1] + diff[i];
    ord.push_back(make_pair(i, cov[i]));
  }
  bit.init(n);
  sort(begin(ord), end(ord), [](const PII &a, const PII &b) -> bool {
    return tie(a.second, a.first) < tie(b.second, b.first);
  });
  for (const PII &p : ord) {
    const int &i = p.first;
    ans_l[i] = bit.ask(i).x + 1;
    bit.add(i, ans_l[i]);
  }
  bit.init(n);
  sort(begin(ord), end(ord), [](const PII &a, const PII &b) -> bool {
    return make_pair(a.second, -a.first) < make_pair(b.second, -b.first);
  });
  for (const PII &p : ord) {
    const int &i = p.first;
    ans_r[i] = bit.ask(n - i + 1).x + 1;
    bit.add(n - i + 1, ans_r[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    chkmax(ans, ans_l[i] + ans_r[i] - 1);
  }
  W(ans);
}
}  // namespace aimi
}  // namespace
int main() {
  aimi::main();
  return 0;
}
