#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int MAX_M = 100000;
const int INF = 1 << 30;
int as[MAX_M + 1], dp[MAX_M], ids0[MAX_M], ids1[MAX_M];
int lis(int n, int *as, int *ids) {
  fill(dp, dp + n, INF);
  int m = 0;
  for (int i = 0; i < n; ++i) {
    ids[i] = upper_bound(dp, dp + n, as[i]) - dp;
    dp[ids[i]] = as[i];
    if (m < ids[i]) m = ids[i];
  }
  return m + 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    as[l]++, as[r]--;
  }
  for (int i = 0; i < m; i++) as[i + 1] += as[i];
  lis(m, as, ids0);
  reverse(as, as + m);
  lis(m, as, ids1);
  reverse(ids1, ids1 + m);
  int maxd = 0;
  for (int i = 0; i < m; i++) {
    int d = ids0[i] + ids1[i] + 1;
    if (maxd < d) maxd = d;
  }
  printf("%d\n", maxd);
  return 0;
}
