#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100006;
int f1[N], f2[N], dp[N];
int line[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, l, r;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    line[l]++;
    line[r + 1]--;
  }
  for (int i = 1; i <= m; i++) line[i] += line[i - 1];
  int len = 0;
  int now;
  for (int i = 1; i <= m; i++) {
    if (line[i] >= dp[len]) {
      dp[++len] = line[i];
      f1[i] = len;
    } else {
      int now = upper_bound(dp + 1, dp + 1 + len, line[i]) - dp;
      dp[now] = line[i];
      f1[i] = now;
    }
  }
  len = 0;
  memset(dp, 0, sizeof(dp));
  for (int i = m; i >= 1; i--) {
    if (line[i] >= dp[len]) {
      dp[++len] = line[i];
      f2[i] = len;
    } else {
      now = upper_bound(dp + 1, dp + 1 + len, line[i]) - dp;
      dp[now] = line[i];
      f2[i] = now;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, f1[i] + f2[i + 1]);
  cout << ans << endl;
  return 0;
}
