#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
#pragma GCC diagnostic ignored "-Wsign-compare"
void LIS(vector<int> nums, vector<int>& dp) {
  vector<int> res;
  for (int i = 0; i < nums.size(); i++) {
    auto it = upper_bound(res.begin(), res.end(), nums[i]);
    if (it == res.end())
      res.push_back(nums[i]);
    else
      *it = nums[i];
    dp[i] = res.size();
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > vals(n);
  for (int i = 0; i < n; i++) {
    cin >> vals[i].first >> vals[i].second;
  }
  vector<int> pref(m + 1, 0);
  for (int i = 0; i < n; i++) {
    pref[vals[i].first - 1]--;
    pref[vals[i].second]++;
  }
  for (int i = m - 1; i >= 0; i--) {
    pref[i] += pref[i + 1];
  }
  vector<int> dpa(m + 1, 0), dpb(m + 1, 0);
  LIS(pref, dpa);
  reverse(pref.begin(), pref.end());
  LIS(pref, dpb);
  int ret = 0;
  for (int i = 0; i <= m; i++) {
    ret = max(ret, dpa[i] - 1 + dpb[m - i] - 1);
  }
  cout << ret << endl;
  42;
  42;
  return 0;
}
