#include <bits/stdc++.h>
constexpr int MAX_N = 100100;
using namespace std;
int n, m;
int s_l[MAX_N], s_r[MAX_N];
int arr[MAX_N];
int pre[MAX_N], suf[MAX_N];
int aux_len;
int aux[MAX_N];
int lis1[MAX_N], lis2[MAX_N];
int main() {
  scanf(" %d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf(" %d %d", &s_l[i], &s_r[i]);
    ++arr[s_l[i]];
    --arr[s_r[i] + 1];
  }
  for (int i = 1; i <= m; ++i) {
    arr[i] += arr[i - 1];
  }
  aux_len = 1;
  aux[0] = -1;
  for (int i = 1; i <= m; ++i) {
    int lo = 0, hi = aux_len;
    while (lo + 1 < hi) {
      int mid = (lo + hi) / 2;
      if (aux[mid] <= arr[i]) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    lis1[i] = hi;
    aux[hi] = arr[i];
    aux_len = max(aux_len, hi + 1);
  }
  aux_len = 1;
  for (int i = m; i >= 1; --i) {
    int lo = 0, hi = aux_len;
    while (lo + 1 < hi) {
      int mid = (lo + hi) / 2;
      if (aux[mid] <= arr[i]) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    lis2[i] = hi;
    aux[hi] = arr[i];
    aux_len = max(aux_len, hi + 1);
  }
  for (int i = 1; i <= m; ++i) {
    lis1[i] = max(lis1[i], lis1[i - 1]);
  }
  for (int i = m; i >= 1; --i) {
    lis2[i] = max(lis2[i], lis2[i + 1]);
  }
  int best = 0;
  for (int i = 1; i < m; ++i) {
    best = max(best, lis1[i] + lis2[i + 1]);
  }
  printf("%d\n", best);
  return 0;
}
