#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005], b[1000005];
int f[100005];
int x[100005];
int fl[100005], fr[100005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d %d", &a[i], &b[i]);
  for (int i = 1; i <= n; i++) {
    f[a[i]]++;
    f[b[i] + 1]--;
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    sum += f[i];
    x[i] = sum;
  }
  memset(f, 0, sizeof(f));
  int maxn = 0;
  f[1] = x[1];
  fl[1] = 1;
  maxn = 1;
  for (int i = 2; i <= m; i++) {
    int l = 0, r = maxn;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (f[mid] <= x[i])
        l = mid;
      else
        r = mid - 1;
    }
    fl[i] = l + 1;
    if (l != maxn)
      f[l + 1] = min(f[l + 1], x[i]);
    else {
      f[l + 1] = x[i];
      maxn++;
    }
  }
  memset(f, 0, sizeof(f));
  maxn = 0;
  f[1] = x[m];
  fr[m] = 1;
  maxn = 1;
  for (int i = m - 1; i >= 1; i--) {
    int l = 0, r = maxn;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (f[mid] <= x[i])
        l = mid;
      else
        r = mid - 1;
    }
    fr[i] = l + 1;
    if (l != maxn)
      f[l + 1] = min(f[l + 1], x[i]);
    else {
      f[l + 1] = x[i];
      maxn++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, fl[i] + fr[i] - 1);
  printf("%d", ans);
}
