#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int pref[MAX_N];
int arr[MAX_N];
int n, m;
vector<int> bes = {0};
vector<int> bes2 = {0};
int ad(int x) {
  int lo = 0, hi = bes.size() - 1;
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    if (bes[mid] <= x)
      lo = mid;
    else
      hi = mid - 1;
  }
  if (lo == bes.size() - 1) bes.push_back(0);
  bes[lo + 1] = x;
  return lo + 1;
}
int ad2(int x) {
  int lo = 0, hi = bes2.size() - 1;
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    if (bes2[mid] <= x)
      lo = mid;
    else
      hi = mid - 1;
  }
  if (lo == bes2.size() - 1) bes2.push_back(0);
  bes2[lo + 1] = x;
  return lo + 1;
}
int lis[MAX_N];
int lds[MAX_N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    pref[l]++;
    pref[r + 1]--;
  }
  arr[0] = pref[0];
  int hi = 1;
  for (int i = 1; i < m; i++) arr[i] = arr[i - 1] + pref[i];
  for (int i = 0; i < m; i++) {
    lis[i] = ad(arr[i]);
  }
  for (int i = (m)-1; i >= 0; i--) {
    lds[i] = ad2(arr[i]);
  }
  for (int i = 0; i < m; i++) {
    hi = max(hi, lis[i] + lds[i] - 1);
  }
  cout << hi << "\n";
}
