#include <bits/stdc++.h>
using namespace std;
int m, n, x, y, f[100010], a[100010], b[100010], c[100010], g[100010], l, r,
    ansn;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    f[x]++;
    f[y + 1]--;
  }
  for (int i = 1; i <= m; i++) a[i] = a[i - 1] + f[i];
  g[0] = 0;
  for (int i = 1; i <= m; i++) g[i] = n + 1;
  for (int i = 1; i <= m; i++) {
    int l = 0, r = m, mid;
    while (l + 1 < r) {
      mid = (l + r) / 2;
      if (g[mid] <= a[i])
        l = mid;
      else
        r = mid;
    }
    if (g[r] <= a[i])
      b[i] = r + 1;
    else
      b[i] = l + 1;
    g[b[i]] = min(g[b[i]], a[i]);
  }
  g[0] = 0;
  for (int i = 1; i <= m; i++) g[i] = n + 1;
  for (int i = m; i >= 1; i--) {
    int l = 0, r = m, mid;
    while (l + 1 < r) {
      mid = (l + r) / 2;
      if (g[mid] <= a[i])
        l = mid;
      else
        r = mid;
    }
    if (g[r] <= a[i])
      c[i] = r + 1;
    else
      c[i] = l + 1;
    g[c[i]] = min(g[c[i]], a[i]);
  }
  for (int i = 1; i <= m; i++) ansn = max(ansn, b[i] + c[i] - 1);
  cout << ansn << endl;
  return 0;
}
