#include <bits/stdc++.h>
using namespace std;
int n, m;
int seg[100005];
int L[100005];
int R[100005];
int bit[100005];
void update(int x, int val) {
  for (int i = x; i <= m; i += (i & -i)) bit[i] = max(bit[i], val);
}
int query(int x) {
  int ret = 0;
  for (int i = x; i > 0; i -= (i & -i)) ret = max(ret, bit[i]);
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    seg[l]++;
    seg[r + 1]--;
  }
  for (int i = 1; i <= m; i++) seg[i] += seg[i - 1];
  for (int i = 1; i <= m; i++) {
    L[i] = query(seg[i] + 1) + 1;
    update(seg[i] + 1, L[i]);
  }
  memset(bit, 0, sizeof(bit));
  for (int i = m; i >= 1; i--) {
    R[i] = query(seg[i] + 1) + 1;
    update(seg[i] + 1, R[i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, max(L[i] + R[i + 1], L[i - 1] + R[i]));
  }
  printf("%d\n", ans);
  return 0;
}
