#include <bits/stdc++.h>
using namespace std;
int num[100005], lis[100005][2], L[100005], nL;
class Node {
 public:
  int l, r, m, cnt;
  Node *L, *R;
} head;
void add(Node *s, int l, int r) {
  if (s->l == l && s->r == r) {
    s->cnt++;
    return;
  }
  if (!(s->R)) {
    s->R = new Node;
    s->R->l = s->m + 1;
    s->R->r = s->r;
    s->R->m = (s->R->l + s->R->r) >> 1;
    s->R->cnt = 0;
    s->L = new Node;
    s->L->l = s->l;
    s->L->r = s->m;
    s->L->cnt = 0;
    s->L->m = (s->L->l + s->L->r) >> 1;
    s->R->R = s->L->R = s->R->L = s->L->L = 0;
  }
  if (l > s->m)
    add(s->R, l, r);
  else if (r <= s->m)
    add(s->L, l, r);
  else {
    add(s->L, l, s->m);
    add(s->R, s->m + 1, r);
  }
}
int f(Node *s, int n) {
  if (!(s->L)) return s->cnt;
  if (n > s->m) return s->cnt + f(s->R, n);
  return s->cnt + f(s->L, n);
}
int main() {
  int n, m, a, b, l, r, mid;
  scanf("%d %d", &n, &m);
  head.l = 1;
  head.r = m;
  head.cnt = 0;
  head.m = (1 + m) >> 1;
  head.R = head.L = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    add(&head, a, b);
  }
  for (int i = 1; i <= m; i++) num[i] = f(&head, i);
  nL = 0;
  for (int i = 1; i <= m; i++) {
    if (!nL || L[nL - 1] <= num[i]) {
      L[nL++] = num[i];
      lis[i][0] = nL;
    } else {
      l = -1;
      r = nL;
      mid = (l + r) >> 1;
      while (l != r - 1) {
        if (L[mid] > num[i])
          r = mid;
        else
          l = mid;
        mid = (l + r) >> 1;
      }
      L[r] = num[i];
      lis[i][0] = r;
    }
  }
  nL = 0;
  for (int i = m; i; i--) {
    if (!nL || L[nL - 1] <= num[i]) {
      L[nL++] = num[i];
      lis[i][1] = nL;
    } else {
      l = -1;
      r = nL;
      mid = (l + r) >> 1;
      while (l != r - 1) {
        if (L[mid] > num[i])
          r = mid;
        else
          l = mid;
        mid = (l + r) >> 1;
      }
      L[r] = num[i];
      lis[i][1] = r;
    }
  }
  mid = 0;
  for (int i = 1; i <= m; i++)
    if (lis[i][0] + lis[i][1] > mid) mid = lis[i][0] + lis[i][1];
  printf("%d\n", mid - 1);
  return 0;
}
