#include <bits/stdc++.h>
using namespace std;
int v[100003], rez_cresc[100003], rez_descresc[100003], cb[100001];
int main() {
  int n, m, x, y, i, ct, pas, nrpt, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    v[x]++;
    v[++y]--;
  }
  for (i = 1; i <= m; i++) v[i] += v[i - 1];
  k = 0;
  for (i = 1; i <= m; i++) cb[i] = n + 1;
  for (i = 1; i <= m; i++) {
    ct = 0;
    pas = 1 << 16;
    while (pas) {
      if (ct + pas <= m && cb[ct + pas] <= v[i]) ct += pas;
      pas /= 2;
    }
    rez_cresc[i] = ct + 1;
    cb[ct + 1] = v[i];
  }
  for (i = 1; i <= m; i++) cb[i] = n + 1;
  k = 0;
  for (i = m; i > 0; i--) {
    ct = 0;
    pas = 1 << 16;
    while (pas) {
      if (ct + pas <= m && cb[ct + pas] <= v[i]) ct += pas;
      pas /= 2;
    }
    rez_descresc[i] = ct + 1;
    cb[ct + 1] = v[i];
  }
  nrpt = 0;
  for (i = 1; i <= m; i++)
    if (nrpt < rez_cresc[i] + rez_descresc[i] - 1)
      nrpt = rez_cresc[i] + rez_descresc[i] - 1;
  printf("%d", nrpt);
  return 0;
}
