#include <bits/stdc++.h>
using namespace std;
const int maxn = 100123;
int n, m, a[maxn], smaller[maxn], bigger[maxn];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    int l, r;
    cin >> l >> r;
    a[l]++, a[r + 1]--;
  }
  for (int i = 1; i < (m + 1); ++i) a[i] += a[i - 1];
  vector<int> res;
  for (int i = 1; i < (m + 1); ++i) {
    auto it = upper_bound(res.begin(), res.end(), a[i]);
    smaller[i] = it - res.begin();
    if (it == res.end())
      res.push_back(a[i]);
    else
      *it = a[i];
  }
  res.clear();
  for (int i = m; i; --i) {
    auto it = upper_bound(res.begin(), res.end(), a[i]);
    bigger[i] = it - res.begin();
    if (it == res.end())
      res.push_back(a[i]);
    else
      *it = a[i];
  }
  int ans = 0;
  for (int i = 1; i < (m + 1); ++i) ans = max(ans, bigger[i] + smaller[i] + 1);
  cout << ans << '\n';
}
