#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[100005];
long long int pre[100005];
long long int bit[100005];
void ini() {
  for (long long int i = 0; i < 100005; i++) bit[i] = 0;
}
void upd(long long int idx, long long int val) {
  idx++;
  for (; idx < 100005; idx += idx & -idx) bit[idx] = max(bit[idx], val);
}
long long int q(long long int idx) {
  idx++;
  long long int ans = 0;
  for (; idx > 0; idx -= idx & -idx) ans = max(ans, bit[idx]);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) {
    long long int l, r;
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  long long int val = 0;
  for (long long int i = 1; i <= m; i++) {
    val += a[i];
    a[i] = val;
  }
  long long int ans = 0;
  ini();
  for (long long int i = 1; i <= m; i++) {
    long long int ok = q(a[i]);
    pre[i] = ok + 1;
    upd(a[i], pre[i]);
  }
  ini();
  for (long long int i = m; i > 0; i--) {
    long long int ok = q(a[i]);
    ans = max(ans, pre[i] + ok);
    upd(a[i], ok + 1);
  }
  cout << ans;
  return 0;
}
