#include <bits/stdc++.h>
using namespace std;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;
    }
  }
}
struct vect {
  struct vect *foll;
  long long val;
  struct vect *succ;
};
int k[100500];
vector<int> a;
vector<int> d;
vector<int> d1;
int n, t[400500];
int sum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return max(sum(v * 2, tl, tm, l, min(r, tm)),
             sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void upd(int v, int tl, int tr, int pos, int val) {
  if (tl == tr)
    t[v] = val;
  else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      upd(v * 2, tl, tm, pos, val);
    else
      upd(v * 2 + 1, tm + 1, tr, pos, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
void lds() {
  d.resize(a.size());
  d[0] = 1;
  upd(1, 0, n, a[0], d[0]);
  for (int i = 1; i < a.size(); i++) {
    int j = sum(1, 0, n, 0, a[i]);
    d[i] = j + 1;
    upd(1, 0, n, a[i], d[i]);
  }
}
void lis() {
  for (int i = 0; i <= 400050; i++) {
    t[i] = 0;
  }
  reverse(a.begin(), a.end());
  d1.resize(a.size());
  d1[0] = 1;
  upd(1, 0, n, a[0], d1[0]);
  for (int i = 1; i < a.size(); i++) {
    int j = sum(1, 0, n, 0, a[i]);
    d1[i] = j + 1;
    upd(1, 0, n, a[i], d1[i]);
  }
  reverse(d1.begin(), d1.end());
}
int main() {
  cin >> n;
  int m;
  cin >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ++k[l];
    --k[r + 1];
  }
  for (int i = 1; i <= m; i++) {
    k[i] += k[i - 1];
    a.push_back(k[i]);
  }
  lds();
  lis();
  int res = 0;
  for (int i = 0; i < a.size(); i++) {
    res = max(res, d[i] + d1[i] - 1);
  }
  cout << res << endl;
  return 0;
}
