#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
using namespace std;
int n, m;
int d[100100];
int l[100100], r[100100];
int dp[100100];
int t[100100];
int get(int pos) {
  int res = 0;
  while (pos >= 0) {
    res = max(res, t[pos]);
    pos = (pos & (pos + 1)) - 1;
  }
  return res;
}
void upd(int pos, int val) {
  while (pos <= n) {
    t[pos] = max(t[pos], val);
    pos |= pos + 1;
  }
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    d[l[i]]++;
    d[r[i] + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    d[i] += d[i - 1];
  }
  int cur = 0;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    dp[i] = get(d[i]) + 1;
    upd(d[i], dp[i]);
    ans = max(ans, dp[i]);
  }
  for (int i = 0; i <= n; i++) t[i] = 0;
  for (int i = m; i > 0; i--) {
    int c = get(d[i]) + 1;
    dp[i] += c - 1;
    upd(d[i], c);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
