#include <bits/stdc++.h>
using namespace std;
const int maxN = 100050;
int d[maxN];
int d_inv[maxN];
int len[maxN];
int len_inv[maxN];
int cnt[maxN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i < maxN; i++) {
    d[i] = maxN;
    d_inv[i] = maxN;
  }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int l = -1, r = maxN;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (d[mid] > cnt[i]) {
        r = mid;
      } else {
        l = mid;
      }
    }
    len[i] = l + 1;
    d[l + 1] = min(d[l + 1], cnt[i]);
  }
  for (int i = m; i >= 1; i--) {
    int l = -1, r = maxN;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (d_inv[mid] > cnt[i]) {
        r = mid;
      } else {
        l = mid;
      }
    }
    len_inv[i] = l + 1;
    d_inv[l + 1] = min(d_inv[l + 1], cnt[i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, len[i] + len_inv[i] - 1);
  }
  cout << ans;
  return 0;
}
