#include <bits/stdc++.h>
#pragma warning(disable : 4996)
FILE *in = stdin, *out = stdout;
using namespace std;
int n, m, cnt[100005], B;
int tree[100005 * 2], L[100005], R[100005];
void input() {
  fscanf(in, "%d", &n);
  fscanf(in, "%d", &m);
  B = n - 1;
  for (int i = (1); i <= (n); i++) {
    int x, y;
    fscanf(in, "%d", &x), fscanf(in, "%d", &y);
    cnt[x]++;
    cnt[y + 1]--;
  }
  for (int i = (1); i <= (m); i++) cnt[i] += cnt[i - 1];
  for (int i = (1); i <= (m); i++) cnt[i]++;
}
void update(int idx, int cnt) {
  idx += B;
  tree[idx] = cnt;
  idx >>= 1;
  while (idx) tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]), idx >>= 1;
}
int find(int L, int R) {
  L += B, R += B;
  int res = 0;
  while (L <= R) {
    if (L & 1) res = max(res, tree[L++]);
    if (!(R & 1)) res = max(res, tree[R--]);
    L >>= 1, R >>= 1;
  }
  return res;
}
void pro() {
  for (int i = (1); i <= (m); i++) {
    L[i] = find(1, cnt[i]) + 1;
    update(cnt[i], L[i]);
  }
  for (int i = (1); i <= (B * 2 + 1); i++) tree[i] = 0;
  for (int i = m; i >= 1; i--) {
    R[i] = find(1, cnt[i]) + 1;
    update(cnt[i], R[i]);
  }
  int ans = 0;
  for (int i = (1); i <= (m); i++) {
    ans = max(ans, L[i] + R[i] - 1);
  }
  fprintf(out, "%d", ans);
}
int main() {
  input();
  pro();
  return 0;
}
