#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;
int cnt[MAXN], f[MAXN], f1[MAXN], f2[MAXN];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
inline void Max(int &x, int y) {
  if (x < y) x = y;
}
int main() {
  int n = read(), m = read(), ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    cnt[x]++, cnt[y + 1]--;
  }
  for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= m; i++) {
    *upper_bound(f, f + m, cnt[i]) = cnt[i];
    f1[i] = lower_bound(f, f + m, INF) - f;
  }
  memset(f, 0x3f, sizeof(f));
  for (int i = m; i >= 1; i--) {
    *upper_bound(f, f + m, cnt[i]) = cnt[i];
    f2[i] = lower_bound(f, f + m, INF) - f;
  }
  for (int i = 1; i <= m; i++) Max(ans, f1[i] + f2[i + 1]);
  printf("%d\n", ans);
  return 0;
}
