#include <bits/stdc++.h>
using namespace std;
int c[100010], pre[100010], suf[100010], t[100010];
vector<pair<int, int> > cc, uc;
void upd(int x, int v) {
  while (x < 100010) {
    t[x] = max(t[x], v);
    x += x & -x;
  }
}
int query(int x) {
  int ret = 0;
  while (x) {
    ret = max(ret, t[x]);
    x -= x & -x;
  }
  return ret;
}
int main() {
  int n, m, l, r;
  cin >> n >> m;
  memset(c, 0, sizeof c);
  memset(t, 0, sizeof t);
  memset(pre, 0, sizeof pre);
  memset(suf, 0, sizeof suf);
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    c[l]++;
    c[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    c[i] += c[i - 1];
    cc.push_back({c[i], i});
    uc.push_back({c[i], m + 1 - i});
  }
  sort(cc.begin(), cc.end());
  sort(uc.begin(), uc.end());
  for (int i = 0; i < m; i++) {
    int tmp = query(cc[i].second);
    pre[cc[i].second] = tmp + 1;
    upd(cc[i].second, tmp + 1);
  }
  memset(t, 0, sizeof t);
  for (int i = 0; i < m; i++) {
    int tmp = query(uc[i].second);
    suf[uc[i].second] = tmp + 1;
    upd(uc[i].second, tmp + 1);
  }
  reverse(suf + 1, suf + m + 1);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, pre[i] + suf[i] - 1);
  }
  cout << ans;
}
