#include <bits/stdc++.h>
using namespace std;
const long long N = 200010;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n, m, a[N], F[N], G[N], C[N], res;
signed main() {
  n = read(), m = read();
  for (register long long i = 1; i <= n; i++) {
    long long l, r;
    l = read(), r = read();
    l--, r--;
    a[l]++, a[r + 1]--;
  }
  for (register long long i = 1; i <= m; i++) a[i] += a[i - 1];
  memset(C, 0x3f, sizeof(C)), C[0] = 0;
  for (register long long i = 0; i < m; i++) {
    long long pos = upper_bound(C, C + m, a[i]) - C - 1;
    pos++;
    C[pos] = min(C[pos], a[i]);
    F[i] = pos;
  }
  memset(C, 0x3f, sizeof(C)), C[0] = 0;
  for (register long long i = m - 1; ~i; i--) {
    long long pos = upper_bound(C, C + m, a[i]) - C - 1;
    pos++;
    C[pos] = min(C[pos], a[i]);
    G[i] = pos;
  }
  for (register long long i = 0; i < m; i++) res = max(res, F[i] + G[i] - 1);
  printf("%lld\n", res);
  return 0;
}
