#include <bits/stdc++.h>
using namespace std;
int arr[100000 + 5], lis_len[100000 + 5], lds_len[100000 + 5];
int fast_lis(int *arr, int N) {
  int ret = 0;
  vector<int> sq;
  int i, lo, hi, mid;
  {
    sq.push_back(arr[1]);
    lis_len[1] = 1;
  }
  for (i = 2; i <= N; i++) {
    if (!sq.size()) {
      sq.push_back(arr[i]);
      lis_len[i] = 1;
      ret = 1;
      continue;
    }
    lo = 0;
    hi = sq.size() - 1;
    if (arr[i] < sq[lo])
      sq[lo] = arr[i], lis_len[i] = 1;
    else if (arr[i] >= sq[hi])
      sq.push_back(arr[i]), lis_len[i] = hi + 2;
    else {
      while (lo < hi) {
        mid = lo + ((hi - lo + 1) >> 1);
        if (sq[mid] <= arr[i])
          lo = mid;
        else
          hi = mid - 1;
      }
      sq[lo + 1] = arr[i];
      lis_len[i] = lo + 2;
    }
    ret = max(ret, lis_len[i]);
  }
  return ret;
}
int main() {
  int n, m, i, l, r, ans = 0;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &l, &r);
    arr[l]++;
    arr[r + 1]--;
  }
  for (i = 1; i <= m; i++) arr[i] += arr[i - 1];
  reverse(arr + 1, arr + m + 1);
  fast_lis(arr, m);
  for (i = 1; i <= m; i++) lds_len[i] = lis_len[i];
  reverse(lds_len + 1, lds_len + m + 1);
  reverse(arr + 1, arr + m + 1);
  fast_lis(arr, m);
  for (i = 1; i <= m; i++) ans = max(ans, lis_len[i] + lds_len[i] - 1);
  printf("%d\n", ans);
  return 0;
}
