#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], h[100005], b[100005], f[100005], ff1[100005], ff2[100005],
    a1[100005];
bool maximize(int &a, int b) {
  if (a < b)
    a = b;
  else
    return false;
  return true;
}
void LIS(int nn) {
  int answer = 0;
  memset(f, 0, sizeof f);
  memset(b, 0, sizeof b);
  for (int i = 1; i <= nn; i++) {
    f[i] = upper_bound(b + 1, b + answer + 1, a1[i]) - b;
    maximize(answer, f[i]);
    b[f[i]] = a1[i];
  }
}
int solve(int u, int v) {
  if (u > v) return 0;
  int sizelen = 0;
  for (int i = u; i <= v; i++) a1[++sizelen] = a[i];
  LIS(sizelen);
  memcpy(ff1, f, sizeof f);
  reverse(a1 + 1, a1 + sizelen + 1);
  LIS(sizelen);
  memcpy(ff2, f, sizeof ff2);
  reverse(ff2 + 1, ff2 + sizelen + 1);
  int res = 0;
  for (int i = 1; i <= sizelen; i++) res = max(res, ff1[i] + ff2[i] - 1);
  return res;
}
void nhap() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int u, v;
    cin >> u >> v;
    a[u]++;
    a[v + 1]--;
  }
}
int main() {
  nhap();
  for (int i = 1; i <= m; i++) a[i] += a[i - 1];
  a[m + 1] = 0;
  int res = 0;
  int j = 1;
  int dem0 = 0;
  int lenmax = 0;
  for (int i = 1; i <= m; i++)
    if (a[i] == 0) dem0++;
  for (int i = 1; i <= m + 1; i++)
    if (a[i] == 0) {
      res = max(res, solve(j, i - 1));
      j = i + 1;
    }
  cout << dem0 + res;
}
