#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > ev;
vector<int> a;
vector<int> la;
vector<int> ra;
vector<int> lk;
inline void init() {
  scanf("%d%d", &n, &m);
  ev.clear();
  int l, r;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &l, &r);
    --l, --r;
    ev.push_back(pair<int, int>(l, 0));
    ev.push_back(pair<int, int>(r, 1));
  }
  sort(ev.begin(), ev.end());
  a.assign(m, 0);
  int k = static_cast<int>(ev.size());
  int cur = 0;
  int cnt = 0;
  for (int i = 0; i < m; ++i) {
    while (cur < k && ev[cur].first == i && !ev[cur].second) {
      ++cnt;
      ++cur;
    }
    a[i] = cnt;
    while (cur < k && ev[cur].first == i) {
      --cnt;
      ++cur;
    }
  }
}
vector<int> t;
int N;
inline int get(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res = max(res, t[r]);
  return res;
}
void upd(int i, int val) {
  for (; i < N; i = (i | (i + 1))) t[i] = max(t[i], val);
}
int main() {
  init();
  la.resize(m);
  vector<int> b(1, 0);
  for (int i = 0; i < m; ++i) {
    int l = 1, r = static_cast<int>(b.size()) - 1;
    int ind = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (b[mid] > a[i]) {
        r = mid - 1;
      } else {
        ind = mid;
        l = mid + 1;
      }
    }
    if (ind + 1 == static_cast<int>(b.size())) {
      la[i] = static_cast<int>(b.size());
      b.push_back(a[i]);
    } else {
      la[i] = ind + 1;
      b[ind + 1] = min(b[ind + 1], a[i]);
    }
  }
  ra.resize(m);
  vector<int> c(1, 0);
  for (int i = m - 1; i >= 0; --i) {
    int l = 1, r = static_cast<int>(c.size()) - 1;
    int ind = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (c[mid] > a[i]) {
        r = mid - 1;
      } else {
        ind = mid;
        l = mid + 1;
      }
    }
    if (ind + 1 == static_cast<int>(c.size())) {
      ra[i] = static_cast<int>(c.size());
      c.push_back(a[i]);
    } else {
      ra[i] = ind + 1;
      c[ind + 1] = min(c[ind + 1], a[i]);
    }
  }
  N = n + 1;
  t.assign(N, 0);
  int res = 0;
  for (int i = m - 1; i >= 0; --i) {
    int cur = la[i];
    cur += get(a[i] - 1);
    upd(a[i], ra[i]);
    res = max(res, cur);
  }
  printf("%d\n", res);
  return 0;
}
