#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 1e5 + 50;
long long f[MaxN], g[MaxN], b[MaxN], n, m;
struct BIT {
  long long a[MaxN];
  inline void init() { std::memset(a, 0, sizeof a); }
  inline void upd(long long x, long long k) {
    ++x;
    while (x <= m + 1) checkmax(a[x], k), x += lowbit(x);
  }
  inline long long ask(long long x) {
    ++x;
    register long long ans = 0;
    while (x) checkmax(ans, a[x]), x ^= lowbit(x);
    return ans;
  }
} tr;
signed main(void) {
  read(n, m);
  register long long l, r;
  while (n--) read(l, r), ++b[l], --b[r + 1];
  for (long long i = 1; i <= m; ++i) b[i] += b[i - 1];
  tr.init();
  for (long long i = 1; i <= m; ++i)
    f[i] = tr.ask(b[i]) + 1, tr.upd(b[i], f[i]);
  tr.init();
  for (long long i = m; i; --i) g[i] = tr.ask(b[i]) + 1, tr.upd(b[i], g[i]);
  register long long ans = 0;
  for (long long i = 0; i <= m; ++i) checkmax(ans, f[i] + g[i + 1]);
  write(ans), std::puts("");
  return 0;
}
