#include <bits/stdc++.h>
const int maxn = 100005;
int dp1[maxn];
int dp2[maxn];
int lowbit(int x) { return x & (-x); }
int n, m;
int a[maxn];
void add(int l, int r) {
  for (int i = l; i <= m; i += lowbit(i)) a[i]++;
  for (int j = r + 1; j <= m; j += lowbit(j)) a[j]--;
}
int query(int pos) {
  int tans = 0;
  for (int i = pos; i; i -= lowbit(i)) tans += a[i];
  return tans;
}
int que[maxn];
int qtot = 0;
int v[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int tp1, tp2;
    scanf("%d%d", &tp1, &tp2);
    add(tp1, tp2);
  }
  for (int i = 1; i <= m; i++) {
    v[i] = query(i);
  }
  for (int i = 1; i <= m; i++) {
    int lc, val;
    if (!qtot) {
      que[++qtot] = v[i];
      val = qtot;
    } else {
      lc = std::upper_bound(que + 1, que + qtot + 1, v[i]) - que;
      if (lc == qtot + 1)
        que[++qtot] = v[i], val = qtot;
      else {
        que[lc] = std::min(que[lc], v[i]);
        val = lc;
      }
    }
    dp1[i] = val;
  }
  qtot = 0;
  for (int i = m; i >= 1; i--) {
    int lc, val;
    if (!qtot) {
      que[++qtot] = v[i];
      val = qtot;
    } else {
      lc = std::upper_bound(que + 1, que + qtot + 1, v[i]) - que;
      if (lc == qtot + 1)
        que[++qtot] = v[i], val = qtot;
      else {
        que[lc] = std::min(que[lc], v[i]);
        val = lc;
      }
    }
    dp2[i] = val;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = std::max(ans, dp1[i] + dp2[i] - 1);
  printf("%d\n", ans);
  return 0;
}
