#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, x, y, a[N], b[N], dp[N], t[N], ans;
inline int get(int pos) {
  int cur = 0;
  for (int i = pos; i >= 0; i &= i + 1, i--) {
    cur = max(cur, t[i]);
  }
  return cur;
}
inline void upd(int pos, int val) {
  for (int i = pos; i < N; i |= i + 1) {
    t[i] = max(t[i], val);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    dp[x] += 1;
    dp[y + 1] -= 1;
  }
  int cur = 0;
  for (int i = 1; i <= m; i++) {
    cur += dp[i];
    a[i] = cur;
    y = get(a[i]) + 1;
    b[i] = y;
    upd(a[i], y);
  }
  reverse(a + 1, a + m + 1);
  memset(t, 0, sizeof(t));
  for (int i = 1; i <= m; i++) {
    y = get(a[i]) + 1;
    ans = max(ans, b[m - i + 1] + y - 1);
    upd(a[i], y);
  }
  cout << ans;
}
