#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 1e5 + 5;
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
int n, m, a[MAXN], b[MAXN], len1[MAXN], len2[MAXN];
void work() {
  int k = 1;
  b[k] = a[1];
  len1[1] = k;
  for (int i = 2; i <= m; i++) {
    if (a[i] >= b[k]) {
      b[++k] = a[i];
    } else {
      int l = 1, r = k;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (a[i] >= b[mid])
          l = mid + 1;
        else
          r = mid - 1;
      }
      b[l] = a[i];
    }
    len1[i] = k;
  }
  k = 1;
  b[k] = a[m];
  len2[m] = k;
  for (int i = m - 1; i >= 1; i--) {
    if (a[i] >= b[k]) {
      b[++k] = a[i];
    } else {
      int l = 1, r = k;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (a[i] >= b[mid])
          l = mid + 1;
        else
          r = mid - 1;
      }
      b[l] = a[i];
    }
    len2[i] = k;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  for (int i = 1, l, r; i <= n; i++) {
    scanf("%d%d", &l, &r);
    a[l]++;
    a[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    a[i] += a[i - 1];
  }
  work();
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, len1[i] + len2[i] - 1);
  }
  printf("%d\n", ans);
}
