#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long segtree1[400010], segtree2[400010];
void update(long long segtree[], long long loc, long long l, long long r,
            long long idx, long long val) {
  if (l > idx || r < idx) {
    return;
  }
  if (l == idx && idx == r) {
    segtree[loc] = val;
    return;
  }
  long long left = 2 * loc, right = 2 * loc + 1, mid = (l + r) >> 1;
  update(segtree, left, l, mid, idx, val);
  update(segtree, right, mid + 1, r, idx, val);
  segtree[loc] = max(segtree[left], segtree[right]);
}
long long query(long long segtree[], long long loc, long long l, long long r,
                long long st, long long en) {
  if (l > r || l > en || r < st) return 0;
  if (st <= l && en >= r) {
    return segtree[loc];
  }
  long long left = 2 * loc, right = 2 * loc + 1, mid = (l + r) >> 1;
  return max(query(segtree, left, l, mid, st, en),
             query(segtree, right, mid + 1, r, st, en));
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, l, r;
  cin >> n >> m;
  vector<long long> pref(m + 2);
  for (long long i = 1; i <= n; i++) {
    cin >> l >> r;
    pref[l]++;
    pref[r + 1]--;
  }
  for (long long i = 0; i <= n; i++) {
    update(segtree1, 1, 0, n, i, 0);
    update(segtree2, 1, 0, n, i, 0);
  }
  vector<long long> prev(m + 2, 0);
  for (long long i = 1; i <= m; i++) {
    pref[i] += pref[i - 1];
    long long cnt = 1 + query(segtree1, 1, 0, n, 0, pref[i]);
    update(segtree1, 1, 0, n, pref[i], cnt);
    prev[i] = cnt;
  }
  long long ans = 1;
  for (long long i = m; i >= 1; i--) {
    ans = max(ans, prev[i] + query(segtree2, 1, 0, n, 0, pref[i]));
    long long cnt = 1 + query(segtree2, 1, 0, n, 0, pref[i]);
    update(segtree2, 1, 0, n, pref[i], cnt);
  }
  cout << ans << endl;
  return 0;
}
