#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  ios_base::sync_with_stdio(0);
  smain();
  return 0;
}
long long n, m;
long long c[200001], a[200001], t[200001], d[200001];
long long get(long long r) {
  long long result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result = max(result, t[r]);
  return result;
}
void update(long long i, long long v) {
  for (; i < 200001; i = (i | (i + 1))) t[i] = max(t[i], v);
}
void smain() {
  for (; cin >> n >> m;) {
    memset(c, 0, sizeof(c));
    for (long long i = 0; i < n; i++) {
      long long l, r;
      cin >> l >> r;
      c[l - 1] += 1;
      c[r] -= 1;
    }
    long long x = 0;
    memset(t, 0, sizeof(t));
    for (long long i = 0; i < m; i++) {
      x += c[i];
      a[i] = x;
      d[i] = get(x) + 1;
      update(x, d[i]);
    }
    memset(t, 0, sizeof(t));
    long long res = 0;
    for (long long i = m - 1; i >= 0; i--) {
      long long v = get(a[i]);
      update(a[i], v + 1);
      res = max(res, d[i] + v);
    }
    cout << res << '\n';
  }
}
