#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 15, MAX_C = 30;
int n, m, ans;
int psum[MAX_N];
int Arr[MAX_N];
int L[MAX_N];
int R[MAX_N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    psum[l]++;
    psum[r]--;
  }
  for (int i = 1; i < m; i++) psum[i] += psum[i - 1];
  memset(Arr, 127, sizeof Arr);
  Arr[0] = 0;
  for (int i = 0; i < m; i++) {
    int ind = upper_bound(Arr, Arr + MAX_N, psum[i]) - Arr;
    Arr[ind] = psum[i];
    ans = max(ans, ind);
    L[i] = ans;
  }
  ans = 0;
  memset(Arr, 127, sizeof Arr);
  Arr[0] = 0;
  for (int i = m - 1; ~i; i--) {
    int ind = upper_bound(Arr, Arr + MAX_N, psum[i]) - Arr;
    Arr[ind] = psum[i];
    ans = max(ans, ind);
    R[i] = ans;
  }
  for (int i = 0; i + 1 < m; i++) ans = max(ans, L[i] + R[i + 1]);
  cout << ans << "\n";
  return 0;
}
