#include <bits/stdc++.h>
struct line {
  int l, w;
  bool operator<(line a) const { return l != a.l ? l < a.l : w > a.w; }
} li[200200];
int N, M, n[100100], re[100100], mi[100100], md[100100], lis[100100],
    lds[100100], i, j, c, m, bi, bd, l, r;
int main() {
  for (scanf("%d%d", &M, &N), i = 0; i < M << 1; i += 2)
    scanf("%d%d", &li[i].l, &li[i + 1].l), li[i + 1].l++, li[i].w = 1,
                                                          li[i + 1].w = -1;
  for (std::sort(li, li + 2 * M), i = 1, c = j = 0; i <= N;
       n[i] = c, re[N - i + 1] = n[i], i++)
    for (; j < M << 1 && li[j].l <= i; j++) c += li[j].w;
  for (bi = i = 1; i <= N;
       mi[l] <= n[i] && l++, mi[l] = n[i], bi == l && bi++, lis[i] = bi, i++)
    for (l = 0, r = bi - 1; l != r;)
      mi[l + r >> 1] <= n[i] ? l = (l + r >> 1) + 1 : r = l + r >> 1;
  for (bd = i = 1; i <= N;
       md[l] <= re[i] && l++, md[l] = re[i], bd == l && bd++, lds[i] = bd, i++)
    for (l = 0, r = bd - 1; l != r;)
      md[l + r >> 1] <= re[i] ? l = (l + r >> 1) + 1 : r = l + r >> 1;
  for (m = i = 1; i <= N; i++)
    m < lis[i] + lds[N - i + 1] && (m = lis[i] + lds[N - i + 1]);
  printf("%d\n", m - 3);
}
