#include <bits/stdc++.h>
using namespace std;
int tmp[200005];
void make_lis(int A[200005], int N, int lis[200005]) {
  for (int i = (0); i <= (N + 1); ++i) lis[i] = tmp[i] = 1000000;
  tmp[0] = -1;
  for (int i = 0; i < (N); ++i) {
    int idx = upper_bound(tmp, tmp + N, A[i]) - tmp;
    tmp[idx] = A[i];
    lis[i] = idx;
  }
}
struct bit_t {
  int A[200005];
  void inc(int i, int v) {
    ++i;
    assert(i >= 0);
    while (i) A[i] += v, i -= (i & (-i));
  }
  int query(int i) {
    ++i;
    assert(i >= 0);
    int ans = 0;
    while (i < 200005) ans += A[i], i += (i & (-i));
    return ans;
  }
} T;
int A[200005];
int forw[200005];
int backw[200005];
int main() {
  int INTERVALS, M, a, b;
  scanf("%d%d", &INTERVALS, &M);
  for (int i = 0; i < (INTERVALS); ++i) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    T.inc(b, 1);
    T.inc(a - 1, -1);
  }
  for (int i = 0; i < (M); ++i) A[i] = T.query(i);
  make_lis(A, M, forw);
  reverse(A, A + M);
  make_lis(A, M, backw);
  reverse(A, A + M);
  reverse(backw, backw + M);
  int ans = 0;
  for (int i = 0; i < (M); ++i) {
    int here = forw[i] + backw[i] - 1;
    ans = max(ans, here);
  }
  cout << ans << endl;
}
