#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int MAXN = 100001;
int fen[MAXN];
int fl[MAXN];
int fr[MAXN];
int c[MAXN];
void init() { memset(fen, 0, sizeof(fen)); }
int n, m;
void upd(int x, int y) {
  assert(x != 0);
  for (int i = x; i <= n; i += i & -i) {
    fen[i] = max(fen[i], y);
  }
}
int gt(int x) {
  int ans = 0;
  assert(x != 0);
  for (int i = x; i > 0; i -= i & -i) {
    ans = max(ans, fen[i]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    ++c[a];
    --c[b + 1];
  }
  for (int i = 2; i <= m; ++i) {
    c[i] += c[i - 1];
  }
  init();
  for (int i = 1; i <= m; ++i) {
    upd(c[i] + 1, fl[i] = (gt(c[i] + 1) + 1));
  }
  init();
  int ans = 0;
  for (int i = m; i >= 1; --i) {
    upd(c[i] + 1, fr[i] = (gt(c[i] + 1) + 1));
    ans = max(ans, fl[i] + fr[i] - 1);
  }
  cout << ans << "\n";
  return 0;
}
