#include <bits/stdc++.h>
using namespace std;
vector<int> lcs(vector<int> &seq) {
  int m = seq.size();
  vector<int> ret(m);
  vector<int> a;
  for (int i = 0; i < m; ++i) {
    if (a.size() == 0) {
      a.push_back(seq[i]);
      ret[i] = 1;
    } else {
      if (seq[i] >= a.back()) {
        a.push_back(seq[i]);
        ret[i] = a.size();
      } else {
        int index = upper_bound(a.begin(), a.end(), seq[i]) - a.begin();
        a[index] = seq[i];
        ret[i] = index;
      };
    };
  };
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> events;
  for (int i = 0; i < m; ++i) {
    events.push_back(make_pair(i, 1));
  };
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    events.push_back(make_pair(l, 0));
    events.push_back(make_pair(r, 2));
  };
  sort(events.begin(), events.end());
  vector<int> count(m);
  int temp = 0;
  for (auto p : events) {
    if (p.second == 0) {
      temp++;
    } else if (p.second == 1) {
      count[p.first] = temp;
    } else {
      temp--;
    };
  };
  auto p = lcs(count);
  reverse(count.begin(), count.end());
  auto q = lcs(count);
  reverse(q.begin(), q.end());
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    int val = p[i] + q[i] - 1;
    ans = max(ans, val);
  };
  cout << ans << endl;
};
