#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
int a[N], cnt[N], pre[N], suf[N];
vector<int> f;
int getP(int x) { return upper_bound(f.begin(), f.end(), x) - f.begin(); }
signed main() {
  ios::sync_with_stdio(false);
  int n, m, l, r;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  for (int i = 1; i <= m; i++) a[i] = a[i - 1] + cnt[i];
  f.clear();
  for (int i = 1; i <= m; i++) {
    if (f.size() == 0 || *f.rbegin() <= a[i])
      f.push_back(a[i]);
    else
      f[getP(a[i])] = a[i];
    pre[i] = f.size();
  }
  f.clear();
  for (int i = m; i; --i) {
    if (f.size() == 0 || *f.rbegin() <= a[i])
      f.push_back(a[i]);
    else
      f[getP(a[i])] = a[i];
    suf[i] = f.size();
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, pre[i] + suf[i + 1]);
  cout << ans << "\n";
  return 0;
}
