#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 2e9;
int a[maxn], cnt[2][maxn], dp[2][maxn], lis[maxn], lds[maxn];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    a[l]++;
    a[r + 1]--;
  }
  cnt[0][1] = a[1];
  for (int i = 1; i < m; i++) {
    cnt[0][i] = cnt[0][i - 1] + a[i];
  }
  for (int i = 0; i < m; i++) {
    cnt[1][i] = cnt[0][m - i - 1];
  }
  dp[0][0] = -inf;
  dp[1][0] = -inf;
  for (int i = 1; i <= m; i++) {
    dp[0][i] = inf;
    dp[1][i] = inf;
  }
  for (int i = 0; i < m; i++) {
    int p = upper_bound(dp[0], dp[0] + m, cnt[0][i]) - dp[0];
    dp[0][p] = cnt[0][i];
    lis[i] = p;
    int q = upper_bound(dp[1], dp[1] + m, cnt[1][i]) - dp[1];
    dp[1][q] = cnt[1][i];
    lds[m - i - 1] = q;
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans = max(ans, lis[i] + lds[i] - 1);
  }
  cout << ans << endl;
}
