#include <bits/stdc++.h>
using namespace std;
const int N = 333358;
const double pi = acos(-1.0);
const int fx[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
const int ff[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
                      {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
const long long MOD = 1000000007LL;
const int MAX = 1000000000;
void gcd(long long a, long long b, long long &d, long long &x, long long &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long inv(long long a, long long n) {
  long long d, x, y;
  gcd(a, n, d, x, y);
  return (x + n) % n;
}
int n, m, a[N], b[N], c[N], d[N], e[N];
int main() {
  int cases;
  cases = 1;
  for (int iii = 1; iii <= cases; ++iii) {
    scanf("%d%d", &m, &n);
    for (int i = 0; i < m; ++i) {
      int x, y;
      scanf("%d%d", &x, &y);
      ++b[x];
      --b[y + 1];
    }
    for (int i = 1; i <= n; ++i) a[i] = a[i - 1] + b[i];
    int mmax = 0;
    for (int i = 1; i <= n; ++i) {
      int temp = upper_bound(c, c + mmax + 1, a[i]) - c;
      if (temp > mmax) ++mmax;
      c[temp] = a[i];
      d[i] = temp;
    }
    memset(c, 0, sizeof(c));
    mmax = 0;
    for (int i = n; i >= 1; --i) {
      int temp = upper_bound(c, c + mmax + 1, a[i]) - c;
      if (temp > mmax) ++mmax;
      c[temp] = a[i];
      e[i] = temp;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) ans = max(ans, d[i] + e[i] - 1);
    printf("%d\n", ans);
  }
}
