#include <bits/stdc++.h>
using namespace std;
const int dd = (int)1e5 + 7;
int A[dd], k[dd], j[dd], G[dd];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    G[l - 1]++, G[r]--;
  }
  int F = 0;
  for (int i = 0; i < m; ++i) A[i] = (F += G[i]);
  vector<int> Y;
  for (int i = 0; i < m; ++i) {
    auto I = upper_bound(Y.begin(), Y.end(), A[i]);
    k[i] = I - Y.begin() + 1;
    if (I == Y.end())
      Y.push_back(A[i]);
    else
      *I = A[i];
  }
  Y = vector<int>(0);
  for (int i = m - 1; i >= 0; --i) {
    auto I = upper_bound(Y.begin(), Y.end(), A[i]);
    j[i] = I - Y.begin() + 1;
    if (I == Y.end())
      Y.push_back(A[i]);
    else
      *I = A[i];
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) ans = max(ans, k[i] + j[i] - 1);
  printf("%d\n", ans);
  return 0;
}
