#include <bits/stdc++.h>
using namespace std;
int a[100000];
int lis1[100000], lis2[100000];
int lis[100000], len;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x - 1]++;
    a[y]--;
  }
  partial_sum(a, a + m, a);
  for (int i = 0; i < m; i++) {
    lis1[i] = len +=
        (&(*lower_bound(lis, lis + len, a[i] + 1) = a[i]) == lis + len);
  }
  memset(lis, 0, len * sizeof(int));
  len = 0;
  for (int i = m - 1; i >= 0; i--) {
    lis2[i] = len +=
        (&(*lower_bound(lis, lis + len, a[i] + 1) = a[i]) == lis + len);
  }
  int ans = 0;
  for (int i = 0; i < m; i++) ans = max(ans, lis1[i] + lis2[i] - 1);
  cout << ans << endl;
  return 0;
}
