#include <bits/stdc++.h>
using namespace std;
int n, m;
int sum[100010];
int f[100010], g[100010];
int t[100010];
inline void change(int x, int f) {
  ++x;
  for (; x <= n; x += x & -x) t[x] = max(t[x], f);
}
inline int query(int x) {
  ++x;
  int ans = 0;
  for (; x; x -= x & -x) ans = max(ans, t[x]);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    sum[x]++;
    sum[y + 1]--;
  }
  for (int i = 1; i <= m; i++) sum[i] += sum[i - 1];
  for (int i = 1; i <= m; i++) {
    f[i] = query(sum[i]) + 1;
    change(sum[i], f[i]);
  }
  memset(t, 0, sizeof(t));
  for (int i = m; i; i--) {
    g[i] = query(sum[i]) + 1;
    change(sum[i], g[i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, f[i] + g[i] - 1);
  printf("%d\n", ans);
}
