#include <bits/stdc++.h>
using namespace std;
int n, m, l, r;
const int maxn = 100007;
int a[maxn], addmark[maxn], dp[maxn], lis[2][maxn], slis[maxn];
int cnt = 0;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &l, &r);
    addmark[l]++;
    addmark[r + 1]--;
  }
  int sum = 0;
  for (int i = 1; i <= m; ++i) {
    sum += addmark[i];
    a[i] = sum;
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= m; ++i) {
    int pos = upper_bound(dp, dp + m, a[i]) - dp;
    dp[pos] = a[i];
    lis[0][i] = pos + 1;
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = m; i >= 1; i--) {
    int pos = upper_bound(dp, dp + m, a[i]) - dp;
    dp[pos] = a[i];
    lis[1][i] = pos + 1;
    slis[i] = max(slis[i + 1], lis[1][i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    ans = max(ans, lis[0][i] + slis[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
