#include <bits/stdc++.h>
using namespace std;
int f[100010];
int dp[100010];
int le[100010], ri[100010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(f, 0, sizeof(f));
  int l, r;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r);
    f[l]++;
    f[r + 1]--;
  }
  for (int i = 2; i <= m; i++) f[i] += f[i - 1];
  memset(dp, 0x3f, sizeof(dp));
  memset(le, 0, sizeof(le));
  memset(ri, 0, sizeof(ri));
  for (int i = 1; i <= m; i++) {
    le[i] = upper_bound(dp + 1, dp + 1 + m, f[i]) - dp;
    dp[le[i]] = f[i];
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = m; i >= 1; i--) {
    ri[i] = upper_bound(dp + 1, dp + 1 + m, f[i]) - dp;
    dp[ri[i]] = f[i];
  }
  for (int i = 1; i <= m; i++) le[i] = max(le[i], le[i - 1]);
  for (int i = m; i >= 1; i--) ri[i] = max(ri[i], ri[i + 1]);
  int ans = 0;
  for (int i = 1; i <= m + 1; i++) {
    ans = max(ans, le[i - 1] + ri[i]);
  }
  printf("%d\n", ans);
}
