#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int re = 0, flag = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch = '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    re = (re << 1) + (re << 3) + ch - '0', ch = getchar();
  return re * flag;
}
int a[100005], s[100010] = {0};
int d[100005];
int ans1[100010], ans2[100010];
struct seg {
  int l, r;
} q[100010];
int main() {
  int n, m, i, j;
  m = read();
  n = read();
  for (i = 1; i <= m; i++) {
    q[i].l = read(), q[i].r = read();
    s[q[i].l - 1]++;
    s[q[i].r]--;
  }
  int tmp = s[0];
  for (i = 1; i <= n; i++) {
    a[i] = tmp;
    tmp += s[i];
  }
  d[1] = a[1];
  int len = 1;
  ans1[1] = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] >= d[len])
      d[++len] = a[i];
    else {
      int j = upper_bound(d + 1, d + len + 1, a[i]) - d;
      d[j] = a[i];
    }
    ans1[i] = len;
  }
  reverse(a + 1, a + n + 1);
  memset(d, 0, sizeof(d));
  d[1] = a[1];
  len = 1;
  ans2[1] = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] >= d[len])
      d[++len] = a[i];
    else {
      int j = upper_bound(d + 1, d + len + 1, a[i]) - d;
      d[j] = a[i];
    }
    ans2[i] = len;
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    ans = max(ans, ans1[i] + ans2[n - i + 1] - 1);
  }
  printf("%d\n", ans);
}
