#include <bits/stdc++.h>
using namespace std;
const int INF32 = 1E9;
const long long INF64 = 4E18;
const long long M = 1E9 + 7;
const double EPS = 1E-9;
const double PI = 2 * acos(0);
int LIS(vector<long long>& a, vector<long long>& res) {
  if ((int)a.size() == 0) return 0;
  vector<long long> L;
  L.push_back(a[0]);
  long long lis = 1;
  res[0] = 1;
  for (int i = 1; i < (int)a.size(); i++) {
    auto ind = upper_bound(L.begin(), L.end(), a[i]);
    if (ind == L.end()) {
      L.push_back(a[i]);
    } else {
      *ind = min(a[i], *ind);
    }
    lis = (int)L.size();
    res[i] = lis;
  }
  return (int)L.size();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<long long> a(m + 2, 0);
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  for (int i = 1; i <= m; ++i) {
    a[i] += a[i - 1];
  }
  vector<long long> aa(m), bb;
  for (int i = 1; i <= m; ++i) {
    aa[i - 1] = a[i];
  }
  bb = aa;
  reverse(bb.begin(), bb.end());
  vector<long long> lis(m), lds(m);
  LIS(aa, lis);
  LIS(bb, lds);
  reverse(lds.begin(), lds.end());
  vector<long long> unimodal(m);
  for (int i = 0; i < m; ++i) {
    unimodal[i] = lis[i] + lds[i] - 1;
  }
  long long ans = max(lis[m - 1], lds[0]);
  ans = max(ans, *max_element(unimodal.begin(), unimodal.end()));
  cout << ans << '\n';
  return 0;
}
