#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e7;
int cnt[maxn], n, m, last[maxn], lisl[maxn], lisr[maxn];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    cnt[l]++, cnt[r]--;
  }
  for (int i = 1; i <= m; i++) cnt[i] = cnt[i - 1] + cnt[i];
  fill_n(last, maxn, inf);
  last[0] = 0;
  for (int i = 0; i < m; i++) {
    int j = upper_bound(last, last + maxn, cnt[i]) - last;
    last[j] = cnt[i];
    lisl[i] = j;
  }
  fill_n(last, maxn, inf);
  last[0] = 0;
  for (int i = m - 1; i >= 0; i--) {
    int j = upper_bound(last, last + maxn, cnt[i]) - last;
    last[j] = cnt[i];
    lisr[i] = j;
  }
  int maxi = 0;
  for (int i = 0; i < m; i++) maxi = max(maxi, lisl[i] + lisr[i] - 1);
  cout << maxi;
}
