#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m, u, v, z = 0, a[100005] = {}, b[100005] = {}, c[100005] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> u >> v, a[u]++, a[v + 1]--;
  for (int i = 1; i <= m; i++) a[i] += a[i - 1];
  vector<int> d = {0};
  for (int i = 1; i <= m; i++) {
    if (a[i] >= d.back())
      b[i] = (int)d.size(), d.push_back(a[i]);
    else {
      auto it = upper_bound(d.begin(), d.end(), a[i]);
      b[i] = (int)(it - d.begin());
      d[b[i]] = a[i];
    }
  }
  d.clear();
  d.push_back(0);
  for (int i = m; i; i--) {
    if (a[i] >= d.back())
      c[i] = (int)d.size(), d.push_back(a[i]);
    else {
      auto it = upper_bound(d.begin(), d.end(), a[i]);
      c[i] = (int)(it - d.begin());
      d[c[i]] = a[i];
    }
  }
  for (int i = 1; i <= m; i++) z = max(z, b[i] + c[i] - 1);
  cout << z;
}
