#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = (long long)1 << 62;
void getLIS(vector<long long> &a, vector<long long> &v) {
  long long N = a.size();
  vector<long long> dp(N, INF);
  v.push_back(0);
  for (long long i = 0; i < N; ++i) {
    *upper_bound(dp.begin(), dp.begin() + N, a[i]) = a[i];
    v.push_back(lower_bound(dp.begin(), dp.begin() + N, INF) - dp.begin());
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> A(M + 1, 0);
  long long res = 0;
  long long l, r;
  for (long long i = 0; i < N; i++) {
    cin >> l >> r;
    l--;
    A[l]++;
    A[r]--;
  }
  for (long long i = 0; i < M; i++) {
    A[i + 1] += A[i];
  }
  A.pop_back();
  vector<long long> v;
  getLIS(A, v);
  reverse(A.begin(), A.end());
  vector<long long> v2;
  getLIS(A, v2);
  reverse(v2.begin(), v2.end());
  for (long long i = 0; i < v.size(); i++) {
    res = max(res, v[i] + v2[i]);
  }
  cout << res << endl;
}
