#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, ans;
int cnt[maxn], sum[maxn], val[maxn];
int up[maxn], down[maxn], top;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &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 t = upper_bound(up + 1, up + top + 1, cnt[i]) - up;
    top = max(top, t);
    up[t] = cnt[i];
    sum[i] += t;
  }
  top = 0;
  for (int i = 1; i <= top; ++i) up[i] = 0;
  for (int i = m; i >= 1; --i) {
    int t = upper_bound(up + 1, up + top + 1, cnt[i]) - up;
    top = max(top, t);
    up[t] = cnt[i];
    sum[i] += t;
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = max(ans, sum[i]);
  printf("%d\n", ans - 1);
}
