#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, t, q, x, z, l, r, y, w, k, n, v, f, x1, y1, d, m, sum, maxi;
  cin >> n;
  cin >> m;
  vector<long long> p(m + 1), a(m), pref(m), syf(m), dp(3 * m + 1);
  for (i = 0; i < m; i++) {
    p[i] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> l;
    cin >> r;
    l--;
    r--;
    p[l]++;
    p[r + 1]--;
  }
  sum = 0;
  for (i = 0; i < m; i++) {
    sum += p[i];
    a[i] = sum;
  }
  for (i = 0; i < 3 * m; i++) {
    dp[i] = 10000000;
  }
  dp[0] = 0;
  l = 0;
  for (i = 0; i < m; i++) {
    x = lower_bound(dp.begin(), dp.end(), a[i] + 1) - dp.begin();
    dp[x] = a[i];
    while (dp[l] < 10000000) {
      l++;
    }
    pref[i] = l - 1;
  }
  for (i = 0; i < 3 * m; i++) {
    dp[i] = 10000000;
  }
  dp[0] = 0;
  l = 0;
  for (i = m - 1; i >= 0; i--) {
    x = lower_bound(dp.begin(), dp.end(), a[i] + 1) - dp.begin();
    dp[x] = a[i];
    while (dp[l] < 10000000) {
      l++;
    }
    syf[i] = l - 1;
  }
  maxi = 0;
  for (i = 0; i < m; i++) {
    maxi = max(maxi, pref[i] + syf[i] - 1);
  }
  cout << maxi << endl;
  return 0;
}
