#include <bits/stdc++.h>
using namespace std;
const int maxn = 100011;
int n, m, s[maxn], t[maxn], L[maxn], R[maxn];
void init() {
  scanf("%d%d", &m, &n);
  for (int i = 1, a, b; i <= m; ++i) scanf("%d%d", &a, &b), s[a]++, s[b + 1]--;
  ++s[1];
  for (int i = 2; i <= n; ++i) s[i] += s[i - 1];
}
void clear() { memset(t, 0, sizeof(t)); }
inline int Query(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans = max(ans, t[x]);
  return ans;
}
inline void insert(int x, int v) {
  for (; x <= m + 1; x += x & -x) t[x] = max(t[x], v);
}
void work() {
  clear();
  for (int i = 1; i <= n; ++i) L[i] = Query(s[i]) + 1, insert(s[i], L[i]);
  clear();
  for (int i = n; i >= 1; --i) R[i] = Query(s[i]) + 1, insert(s[i], R[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, L[i] + R[i]);
  printf("%d\n", --ans);
}
int main() {
  init();
  work();
  return 0;
}
