#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, bool> p[200002];
int a[100002];
int dpl[100002], dpr[100002];
int ans = 0;
stack<int> s;
int t[500005];
int lazy[500005];
void updlazy(int pos) {
  t[pos] = max(t[pos], lazy[pos]);
  lazy[2 * pos] = max(lazy[2 * pos], lazy[pos]);
  lazy[2 * pos + 1] = max(lazy[2 * pos + 1], lazy[pos]);
  lazy[pos] = 0;
}
int query(int l, int r, int ql, int qr, int pos) {
  if (r < ql || l > qr) return 0;
  if (lazy[pos] > 0) updlazy(pos);
  if (l >= ql && r <= qr) return t[pos];
  int mid = (l + r) / 2;
  return max(query(l, mid, ql, qr, 2 * pos),
             query(mid + 1, r, ql, qr, 2 * pos + 1));
}
void update(int l, int r, int x, int val, int pos) {
  if (x < l || x > r) return;
  t[pos] = max(t[pos], val);
  if (l == r) return;
  int mid = (l + r) / 2;
  update(l, mid, x, val, 2 * pos);
  update(mid + 1, r, x, val, 2 * pos + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    p[2 * i] = {l, 1};
    p[2 * i + 1] = {r, 0};
  }
  for (int i = 0; i < 2 * n; i++) {
    if (p[i].second)
      a[p[i].first]++;
    else
      a[p[i].first + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    a[i] += a[i - 1];
  }
  dpl[1] = 1;
  update(0, n, a[1], 1, 1);
  for (int i = 2; i <= m; i++) {
    dpl[i] = query(0, n, 0, a[i], 1) + 1;
    update(0, n, a[i], dpl[i], 1);
  }
  for (int i = 0; i < 500005; i++) t[i] = 0;
  dpr[m] = 1;
  update(0, n, a[m], 1, 1);
  for (int i = m - 1; i > 0; i--) {
    dpr[i] = query(0, n, 0, a[i], 1) + 1;
    update(0, n, a[i], dpr[i], 1);
  }
  for (int i = 1; i <= m; i++) {
    ans = max(ans, dpr[i] + dpl[i] - 1);
  }
  cout << ans << '\n';
  return 0;
}
