#include <bits/stdc++.h>
using namespace std;
;
vector<long long> lnds(vector<long long> &a) {
  vector<long long> dp(((long long)(a).size()) + 1, 1e9),
      res(((long long)(a).size()));
  dp[1] = a[0];
  res[0] = 1;
  for (long long i = (1); i < (((long long)(a).size())); ++i) {
    long long l = 1, r = ((long long)(dp).size()) + 1;
    while (l < r) {
      long long s = (l + r) / 2;
      if (dp[s] <= a[i])
        l = s + 1;
      else
        r = s;
    }
    dp[l] = a[i];
    res[i] = l;
  }
  return res;
}
void pv(vector<long long> &v) {
  for (auto i = (v).begin(); i != (v).end(); ++i) cout << *i << " ";
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > a(m, {0, 0});
  for (long long i = (0); i < (n); ++i) {
    long long b, e;
    cin >> b >> e;
    b--;
    e--;
    a[b].first++;
    a[e].second++;
  }
  vector<long long> cnt(m);
  long long c = 0;
  for (long long i = (0); i < (m); ++i) {
    c += a[i].first;
    cnt[i] = c;
    c -= a[i].second;
  }
  vector<long long> rcnt = cnt;
  reverse((rcnt).begin(), (rcnt).end());
  vector<long long> seq = lnds(cnt), rseq = lnds(rcnt);
  long long res = 0;
  for (long long i = (0); i < (m); ++i) {
    res = max(res, seq[i] + rseq[m - 1 - i] - 1);
  }
  cout << res << endl;
  return 0;
}
