#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
const int maxn = 1e5 + 10;
int a[maxn], n, m, pre[maxn], suf[maxn], w[maxn], add[maxn];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    add[l]++;
    add[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    a[i] = a[i - 1] + add[i];
  }
  memset(w, INF, sizeof(w));
  w[0] = 0;
  for (int i = 1; i <= m; i++) {
    int len = upper_bound(w, w + m, a[i]) - w;
    pre[i] = len;
    w[len] = a[i];
  }
  memset(w, INF, sizeof(w));
  w[0] = 0;
  for (int i = m; i >= 1; i--) {
    int len = upper_bound(w, w + m, a[i]) - w;
    suf[i] = len;
    w[len] = a[i];
  }
  int ans = -1;
  for (int i = 1; i <= m; i++) ans = max(ans, pre[i] + suf[i] - 1);
  printf("%d\n", ans);
  return 0;
}
