#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  int ouverture[100002], ouverture2[100002];
  int left[100002], right[100002];
  multiset<int> L;
  multiset<int>::iterator it;
  scanf("%d %d", &n, &m);
  for (int i = int(0); i <= int(m); i++) ouverture[i] = 0;
  for (int i = int(1); i <= int(n); i++) {
    scanf("%d %d", &a, &b);
    ouverture[a]++;
    ouverture[b + 1]--;
    ouverture2[b]++;
    ouverture2[a - 1]--;
  }
  L.insert(ouverture[1]);
  int encours = ouverture[1];
  left[1] = 1;
  for (int i = int(2); i <= int(m); i++) {
    encours += ouverture[i];
    it = L.upper_bound(encours);
    if (it != L.end()) L.erase(it);
    L.insert(encours);
    left[i] = L.size();
  }
  L.clear();
  L.insert(ouverture2[m]);
  right[m] = 1;
  encours = ouverture2[m];
  for (int i = m - 1; i >= 1; i--) {
    encours += ouverture2[i];
    it = L.upper_bound(encours);
    if (it != L.end()) L.erase(it);
    L.insert(encours);
    right[i] = L.size();
  }
  int best = 0;
  for (int i = int(1); i <= int(m); i++) {
    best = max(best, left[i] + right[i] - 1);
  }
  printf("%d\n", best);
  return 0;
}
