#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long n, m, k, q, x, y, f, val, t, i, j;
long long ind, sz, sm, ans, mx, mn;
long long a[1000004], l[1000004], r[1000004], vl[1000004], vr[1000004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("myfile.txt", "w", stdout);
    freopen("inp.txt", "r", stdin);
  }
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    a[x]++;
    a[y + 1]--;
  }
  for (i = 1; i < m + 1; i++) a[i] += a[i - 1];
  multiset<int> s;
  for (i = 1; i < m + 1; i++) {
    auto it = s.upper_bound(a[i]);
    if (it != s.end()) s.erase(it);
    s.insert(a[i]);
    l[i] = s.size();
    vl[i] = *s.rbegin();
  }
  s.clear();
  for (i = m; i >= 1; i--) {
    auto it = s.upper_bound(a[i]);
    if (it != s.end()) s.erase(it);
    s.insert(a[i]);
    r[i] = s.size();
    vr[i] = *s.rbegin();
  }
  ans = max(l[m], r[1]);
  long long sh = 0;
  for (i = 2; i < m; i++) {
    ans = max(ans, r[i] + l[i - 1]);
    ans = max(ans, l[i] + r[i + 1]);
  }
  cout << ans;
  return 0;
}
