#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
int tr[100005];
int lb(int x) { return x & (-x); }
void add(int x, int v) {
  while (x <= 100000) {
    tr[x] = max(tr[x], v);
    x += lb(x);
  }
}
int get(int x) {
  int ans = 0;
  while (x > 0) {
    ans = max(ans, tr[x]);
    x -= lb(x);
  }
  return ans;
}
int ans1[100005];
int ans2[100005];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(a, 0, sizeof(a));
    memset(tr, 0, sizeof(tr));
    for (int i = 0; i < n; i++) {
      int l, r;
      scanf("%d%d", &l, &r);
      a[l]++;
      a[r + 1]--;
    }
    for (int i = 2; i <= m; i++) {
      a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; i++) a[i]++;
    for (int i = 1; i <= m; i++) {
      ans1[i] = get(a[i]) + 1;
      add(a[i], ans1[i]);
    }
    memset(tr, 0, sizeof(tr));
    for (int i = m; i >= 1; i--) {
      ans2[i] = get(a[i]) + 1;
      add(a[i], ans2[i]);
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      ans = max(ans, ans1[i] + ans2[i] - 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
