#include <bits/stdc++.h>
static const int Infinity = 1e9;
static void LIS(std::vector<int> &v, std::vector<int> &result, int n) {
  std::vector<int> dp(n + 1);
  dp[0] = -Infinity;
  for (int i = 1; i <= n; i++) dp[i] = Infinity;
  for (int i = 1; i <= n; i++) {
    int max_length =
        (int)(std::upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin());
    dp[max_length] = std::min(dp[max_length], v[i]);
    result[i] = max_length;
  }
}
int main(int argc, const char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::vector<int> v(m + 2);
  for (int i = 0; i < n; i++) {
    int l, r;
    std::cin >> l >> r;
    v[l + 0]++;
    v[r + 1]--;
  }
  for (int i = 1; i <= m; i++) v[i] += v[i - 1];
  std::vector<int> result0(m + 1), result1(m + 1);
  LIS(v, result0, m);
  std::reverse(v.begin(), v.end());
  LIS(v, result1, m);
  int result = 0;
  for (int i = 1; i <= m; i++)
    result = std::max(result, result0[i] + result1[m - i]);
  std::cout << result << std::endl;
  return 0;
}
