#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
int n, m, arr[maxn], cup[maxn], len, pre[maxn], suc[maxn];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    ++arr[l];
    --arr[r + 1];
  }
  len = 0;
  for (int i = 1; i <= m; ++i) {
    arr[i] += arr[i - 1];
    if (!len || arr[i] >= cup[len])
      cup[++len] = arr[i], pre[i] = len;
    else {
      int id = upper_bound(cup + 1, cup + len + 1, arr[i]) - cup;
      cup[id] = arr[i];
      pre[i] = id;
    }
  }
  reverse(arr + 1, arr + m + 1);
  len = 0;
  for (int i = 1; i <= m; ++i) {
    if (!len || arr[i] >= cup[len])
      cup[++len] = arr[i], suc[i] = len;
    else {
      int id = upper_bound(cup + 1, cup + len + 1, arr[i]) - cup;
      cup[id] = arr[i];
      suc[i] = id;
    }
  }
  int ret = 0;
  for (int i = 1; i <= m; ++i) {
    ret = max(ret, pre[i] + suc[m - i + 1] - 1);
  }
  printf("%d\n", ret);
  return 0;
}
