#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005], b[100005], c[100005], fen[100005];
void fenAdd(int pos, int val) {
  for (; pos < 100005; pos |= pos + 1) {
    fen[pos] = max(fen[pos], val);
  }
}
int fenGet(int pos) {
  int res = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    res = max(res, fen[pos]);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); ++i) {
    int from, to;
    scanf("%d%d", &from, &to), --from, --to;
    ++a[from];
    --a[to + 1];
  }
  for (int i = 0; i < (int)(m); ++i) a[i + 1] += a[i];
  assert(a[m] == 0);
  for (int i = 0; i < (int)(100005); ++i) fen[i] = 0;
  for (int i = 0; i < (int)(m); ++i) {
    int cur = fenGet(a[i]) + 1;
    fenAdd(a[i], cur);
    b[i] = cur;
  }
  for (int i = 0; i < (int)(100005); ++i) fen[i] = 0;
  for (int i = m - 1; i >= 0; --i) {
    int cur = fenGet(a[i]) + 1;
    fenAdd(a[i], cur);
    c[i] = cur;
  }
  int ans = 0;
  for (int i = 0; i < (int)(m); ++i) {
    ans = max(ans, b[i] + c[i] - 1);
  }
  cout << ans << endl;
  return 0;
}
