#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 1e5 + 5;
int n, m, s[N], f[N], g[N], T[N], ans;
void up(int x, int v) {
  while (x <= n + 1) {
    T[x] = max(T[x], v);
    x += (x & -x);
  }
}
int que(int x) {
  int res = 0;
  while (x) {
    res = max(res, T[x]);
    x -= (x & -x);
  }
  return res;
}
signed main() {
  read(n);
  read(m);
  for (int i = 1, l, r; i <= n; i++) {
    read(l);
    read(r);
    s[l]++;
    s[r + 1]--;
  }
  s[0] = 1;
  for (int i = 1; i <= m; i++) s[i] += s[i - 1];
  for (int i = 1; i <= m; i++) up(s[i], f[i] = que(s[i]) + 1);
  for (int i = 0; i <= n + 1; i++) T[i] = 0;
  for (int i = m; i >= 1; i--) up(s[i], g[i] = que(s[i]) + 1);
  for (int i = 1; i <= m; i++) ans = max(ans, f[i] + g[i] - 1);
  write(ans);
}
