#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int maxn = 100 * 1000 + 5;
int cnt[maxn], L[maxn], R[maxn];
int lis[maxn];
void LIS(int a[], int n, int L[]) {
  int len = 0;
  for (int i = 0; i < n; i++) {
    int it = upper_bound(lis, lis + len, a[i]) - lis;
    lis[it] = a[i];
    L[i] = it + 1;
    len = max(len, L[i]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n = in(), m = in();
  for (int i = 0; i < n; i++) {
    cnt[in() - 1]++;
    cnt[in()]--;
  }
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  LIS(cnt, m, L);
  reverse(cnt, cnt + m);
  LIS(cnt, m, R);
  reverse(R, R + m);
  int res = 0;
  for (int i = 0; i < m; i++) res = max(res, L[i] + R[i] - 1);
  cout << res << endl;
  return 0;
}
