#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int arr[MAX], lis[MAX], lds[MAX];
int n, m;
void preprocess() {
  multiset<int> s;
  for (int i = 1; i <= m; ++i) {
    s.insert(arr[i]);
    auto it = s.upper_bound(arr[i]);
    if (it != s.end()) s.erase(it);
    lis[i] = s.size();
  }
  s.clear();
  for (int i = m; i >= 1; --i) {
    s.insert(arr[i]);
    auto it = s.upper_bound(arr[i]);
    if (it != s.end()) s.erase(it);
    lds[i] = s.size();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    arr[l]++, arr[r + 1]--;
  }
  for (int i = 1; i <= m; ++i) arr[i] += arr[i - 1];
  preprocess();
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = max(ans, lis[i] + lds[i] - 1);
  return cout << ans << "\n", 0;
}
