#include <bits/stdc++.h>
using namespace std;
int n, m, w[100005], f[100005], g[100005], a[100005];
void solve(int *f) {
  memset(a, 0x3f, sizeof(a));
  for (int i = 1; i <= m; i++) {
    f[i] = 1;
    int l = 1, r = m, mid, pos = 0;
    while (l <= r) {
      mid = l + r >> 1;
      if (a[mid] <= w[i])
        pos = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    f[i] = pos + 1;
    if (a[f[i]] > w[i]) a[f[i]] = w[i];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, l, r; i <= n; i++) {
    scanf("%d%d", &l, &r);
    w[l]++;
    w[r + 1]--;
  }
  for (int i = 1; i <= m; i++) w[i] += w[i - 1];
  solve(f);
  for (int i = 1; i <= m / 2; i++) swap(w[i], w[m - i + 1]);
  solve(g);
  for (int i = 1; i <= m / 2; i++) swap(g[i], g[m - i + 1]);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, f[i] + g[i] - 1);
  }
  printf("%d", ans);
  return 0;
}
