#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int cnt[N];
int tree[N << 2], pre[N], suf[N];
void build(int node, int l, int r) {
  tree[node] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  int left = node << 1;
  int right = left + 1;
  build(left, l, mid);
  build(right, mid + 1, r);
  return;
}
void update(int node, int l, int r, int ind, int val) {
  if (l == r) {
    tree[node] = val;
    return;
  }
  int mid = (l + r) >> 1;
  int left = node << 1;
  int right = left + 1;
  if (ind <= mid)
    update(left, l, mid, ind, val);
  else
    update(right, mid + 1, r, ind, val);
  tree[node] = max(tree[left], tree[right]);
  return;
}
int query(int node, int l, int r, int a, int b) {
  if (l == a && r == b) return tree[node];
  int mid = (l + r) >> 1;
  int left = node << 1;
  int right = left + 1;
  if (b <= mid)
    return query(left, l, mid, a, b);
  else if (a > mid)
    return query(right, mid + 1, r, a, b);
  return max(query(left, l, mid, a, mid), query(right, mid + 1, r, mid + 1, b));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, l, r;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= m; i++) {
    pre[i] = query(1, 0, n, 0, cnt[i]) + 1;
    update(1, 0, n, cnt[i], pre[i]);
  }
  build(1, 0, n);
  for (int i = m; i > 0; i--) {
    suf[i] = query(1, 0, n, 0, cnt[i]) + 1;
    update(1, 0, n, cnt[i], suf[i]);
  }
  for (int i = 1; i <= m; i++) pre[i] = max(pre[i], pre[i - 1]);
  for (int i = m; i > 0; i--) suf[i] = max(suf[i], suf[i + 1]);
  int ans = 0;
  for (int i = 0; i <= m; i++) {
    ans = max(ans, pre[i] + suf[i + 1]);
  }
  cout << ans << "\n";
  return 0;
}
