#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int a[100005], b[100005], f[100005], g[100005];
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 1; i <= (n); ++i) scanf("%d%d", &x, &y), ++a[x], --a[y + 1];
  for (int i = 1; i <= (m); ++i) a[i] += a[i - 1];
  memset(b, 0x3f, sizeof b);
  b[0] = 0;
  for (int i = 1; i <= (m); ++i) {
    f[i] = lower_bound(b, b + m + 1, a[i] + 1) - b;
    b[f[i]] = min(b[f[i]], a[i]);
  }
  reverse(a + 1, a + m + 1);
  memset(b, 0x3f, sizeof b);
  b[0] = 0;
  for (int i = 1; i <= (m); ++i) {
    g[i] = lower_bound(b, b + m + 1, a[i] + 1) - b;
    b[g[i]] = min(b[g[i]], a[i]);
  }
  for (int i = 1; i <= (m); ++i) ans = max(ans, f[i] + g[m - i + 1] - 1);
  printf("%d", ans);
  return 0;
}
