#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
struct segmenttree {
  struct seg {
    int l, r, val;
    seg() { l = r = val = 0; }
  } t[N << 2];
  void build(int p, int l, int r) {
    t[p].l = l;
    t[p].r = r;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(p * 2, l, mid);
    build(p * 2 + 1, mid + 1, r);
  }
  void modify(int p, int x, int d) {
    if (t[p].l == t[p].r) {
      t[p].val = d;
      return;
    }
    int mid = (t[p].l + t[p].r) / 2;
    if (x <= mid)
      modify(p * 2, x, d);
    else
      modify(p * 2 + 1, x, d);
    t[p].val = max(t[p * 2].val, t[p * 2 + 1].val);
  }
  int query(int p, int l, int r) {
    if (l <= t[p].l && t[p].r <= r) return t[p].val;
    int mid = (t[p].l + t[p].r) / 2, ans = 0;
    if (l <= mid) ans = max(ans, query(p * 2, l, r));
    if (r > mid) ans = max(ans, query(p * 2 + 1, l, r));
    return ans;
  }
} a, b;
int c[N], d[N];
int f1[N], f2[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    c[l]++;
    c[r + 1]--;
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    sum += c[i];
    d[i] = sum;
  }
  a.build(1, 0, n);
  b.build(1, 0, n);
  for (int i = 1; i <= m; i++) {
    f1[i] = a.query(1, 0, d[i]) + 1;
    a.modify(1, d[i], f1[i]);
  }
  for (int i = m; i; i--) {
    f2[i] = b.query(1, 0, d[i]) + 1;
    b.modify(1, d[i], f2[i]);
  }
  int ans = 0;
  for (int i = 0; i <= m; i++) ans = max(ans, f1[i] + f2[i + 1]);
  printf("%d", ans);
  return 0;
}
