#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
vector<int> las(const vector<int>& v) {
  vector<int> dp(v.size() + 1, INF);
  vector<int> ans(v.size());
  dp[0] = -1;
  for (int i = 0; i < v.size(); ++i) {
    int j = distance(dp.begin(), upper_bound(dp.begin(), dp.end(), v[i]));
    ans[i] = j;
    dp[j] = v[i];
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<array<int, 2>> lrs;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    lrs.push_back({l - 1, 1});
    lrs.push_back({r, -1});
  }
  sort(lrs.begin(), lrs.end());
  vector<int> counts(m);
  int curr = 0;
  for (int i = 0, j = 0; i < m; ++i) {
    for (; j < lrs.size() && lrs[j][0] == i; ++j) {
      curr += lrs[j][1];
    }
    counts[i] = curr;
  }
  vector<int> forward = las(counts);
  reverse(counts.begin(), counts.end());
  vector<int> backward = las(counts);
  reverse(backward.begin(), backward.end());
  int ans = -1;
  for (int i = 0; i <= m; ++i) {
    int curr_ans = 0;
    if (i != 0) {
      curr_ans += forward[i - 1];
    }
    if (i != m) {
      curr_ans += backward[i];
    }
    ans = max(ans, curr_ans);
  }
  cout << ans;
  return 0;
}
