#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char s;
  s = getchar();
  long long a = 0, f = 1;
  while (!isdigit(s)) {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (isdigit(s)) {
    a = a * 10 + s - '0';
    s = getchar();
  }
  return a * f;
}
int n, m, a[100005], mans, f[100005], t[100005], ma[100005], mapos[100005],
    st[100005], cur;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    int l = read();
    int r = read();
    a[l]++;
    a[r + 1]--;
  }
  for (int i = 1; i <= m; i++) a[i] += a[i - 1];
  cout << endl;
  for (int i = 1; i <= m; i++) {
    if (a[i] >= st[cur]) {
      st[++cur] = a[i];
      f[i] = cur;
    } else {
      int sp = upper_bound(st, st + cur + 1, a[i]) - st;
      st[sp] = a[i];
      f[i] = sp;
    }
  }
  cur = 0;
  memset(st, 0, sizeof(st));
  for (int i = m; i; i--) {
    if (a[i] >= st[cur]) {
      st[++cur] = a[i];
      t[i] = cur;
    } else {
      int sp = upper_bound(st, st + cur + 1, a[i]) - st;
      st[sp] = a[i];
      t[i] = sp;
    }
  }
  for (int i = 1; i <= m; i++) mans = max(mans, f[i] + t[i] - 1);
  cout << mans;
}
