#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
  return w * f;
}
long long n, m, a[100005], f[100005], l1[100005], l2[100005];
long long lis(long long* x) {
  long long len = 1;
  return len;
}
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) a[read()]++, a[read() + 1]--;
  for (long long i = 1; i <= m; i++) a[i] += a[i - 1];
  memset(f, 0, sizeof(f));
  long long len = 1;
  f[1] = a[1], l1[1] = 1;
  for (long long i = 2; i <= m; i++) {
    if (a[i] >= f[len])
      f[++len] = a[i];
    else
      f[upper_bound(f + 1, f + len + 1, a[i]) - f] = a[i];
    l1[i] = len;
  }
  reverse(a + 1, a + m + 1);
  memset(f, 0, sizeof(f));
  len = 1, f[1] = a[1], l2[1] = 1;
  for (long long i = 2; i <= m; i++) {
    if (a[i] >= f[len])
      f[++len] = a[i];
    else
      f[upper_bound(f + 1, f + len + 1, a[i]) - f] = a[i];
    l2[i] = len;
  }
  reverse(l2 + 1, l2 + m + 1);
  long long ans = 0;
  for (long long i = 1; i <= m; i++) ans = max(ans, l1[i] + l2[i] - 1);
  printf("%lld\n", ans);
  return 0;
}
