#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 202010;
const int MX = 200000;
int n, m, pre[N], l, r, seg[4 * N], inc[N];
void update(int n, int s, int e, int at, int val) {
  if (s > at || e < at) return;
  if (s == e) {
    seg[n] = val;
    return;
  }
  update(2 * n, s, (s + e) / 2, at, val);
  update(2 * n + 1, (s + e) / 2 + 1, e, at, val);
  seg[n] = max(seg[2 * n], seg[2 * n + 1]);
}
int get(int n, int s, int e, int l, int r) {
  if (s > r || e < l) return -oo;
  if (s >= l && e <= r) {
    return seg[n];
  }
  return max(get(2 * n, s, (s + e) / 2, l, r),
             get(2 * n + 1, (s + e) / 2 + 1, e, l, r));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &l, &r);
    pre[l]++;
    pre[r + 1]--;
  }
  for (int i = 1; i <= m; ++i) {
    pre[i] += pre[i - 1];
  }
  for (int i = 1; i <= m; ++i) pre[i]++;
  int res = 0;
  for (int i = 1; i <= m; ++i) {
    update(1, 1, MX, i, -oo);
  }
  for (int i = 1; i <= m; ++i) {
    int cur = 1;
    cur = max(cur, 1 + get(1, 1, MX, 1, pre[i]));
    update(1, 1, MX, pre[i], cur);
    inc[i] = cur;
  }
  for (int i = 1; i <= m; ++i) {
    update(1, 1, MX, pre[i], -oo);
  }
  for (int i = m; i >= 1; --i) {
    int cur = 1;
    cur = max(cur, 1 + get(1, 1, MX, 1, pre[i]));
    update(1, 1, MX, pre[i], cur);
    res = max(res, cur - 1 + inc[i]);
  }
  cout << res << endl;
  return 0;
}
