#include <bits/stdc++.h>
using namespace std;
const int maxn = 101010;
const int inf = 1e9;
int cnt[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  int add = 0;
  for (int i = 1; i <= m; i++) {
    add += cnt[i];
    cnt[i] = add;
  }
  int dp[m + 2], dpr[m + 2];
  int ans[m + 2], ansr[m + 2];
  fill(dp, dp + m + 2, inf);
  fill(dpr, dpr + m + 2, inf);
  dp[0] = dpr[0] = 0;
  for (int i = 1, j = m; i <= m; i++, j--) {
    auto it = upper_bound(dp, dp + m + 2, cnt[i]) - dp;
    dp[it] = cnt[i];
    ans[i] = it;
    it = upper_bound(dpr, dpr + m + 2, cnt[j]) - dpr;
    dpr[it] = cnt[j];
    ansr[j] = it;
  }
  int best = 0;
  for (int i = 1; i <= m; i++) {
    best = max(best, ans[i] + ansr[i] - 1);
  }
  cout << best << '\n';
  return 0;
}
