#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
constexpr int infValue =
    std::is_same<T, int>::value ? 2000000007 : 8600000000000000007ll;
template <typename T>
constexpr int maxValue =
    std::is_same<T, int>::value ? 1000000007 : 1000000000000000001ll;
const int INF = infValue<int>;
const int MOD = 1000000007ll;
const double EPS = 1e-6;
const int MAX = maxValue<int>;
int n, m;
int c[100101];
int lp[100101], rp[100101];
int t[100101], answ;
int main(void) {
  scanf("%d %d", &n, &m);
  int l, r;
  while (n--) scanf("%d %d", &l, &r), ++c[l], --c[++r];
  for (register int i = 1; i <= m + 1; ++i) c[i] += c[i - 1];
  memset(t, INF, sizeof(t));
  for (register int i = 1; i <= m; ++i) {
    int j = upper_bound(t, t + 100101, c[i]) - t;
    t[j] = c[i];
    lp[i] = j;
  }
  memset(t, INF, sizeof(t));
  for (register int i = m; i >= 1; --i) {
    int j = upper_bound(t, t + 100101, c[i]) - t;
    t[j] = c[i];
    rp[i] = j;
  }
  for (register int i = 1; i <= m; ++i) answ = max(answ, lp[i] + 1 + rp[i]);
  printf("%d\n", answ);
  return 0;
}
