#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T>
constexpr T inf;
template <>
constexpr int inf<int> = 1e9;
template <>
constexpr ll inf<ll> = 1e18;
template <>
constexpr double inf<double> = 1e18;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> sum(m + 1);
  for (int i = 0; i < n; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    sum[l - 1] += 1;
    sum[r] -= 1;
  }
  for (int i = 0; i < m; ++i) {
    sum[i + 1] += sum[i];
  }
  vector<int> left(m + 1), right(m + 1);
  vector<int> dp(m + 1, inf<int>);
  for (int i = 0; i < m; ++i) {
    *upper_bound(begin(dp), end(dp), sum[i]) = sum[i];
    left[i] = lower_bound(begin(dp), end(dp), inf<int>) - begin(dp);
  }
  dp = vector<int>(m + 1, inf<int>);
  for (int i = m - 1; i >= 0; --i) {
    *upper_bound(begin(dp), end(dp), sum[i]) = sum[i];
    right[i] = lower_bound(begin(dp), end(dp), inf<int>) - begin(dp);
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    ans = max(ans, right[i] + left[i] - 1);
  }
  cout << ans << endl;
}
