#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int INF = 1e9 + 5;
vector<int> lisRES, lisDP, lisPadre, LIS;
void lisrec_increasing(int i, vector<int> &A) {
  if (i == -1) return;
  lisRES.push_back(A[i]);
  lisrec_increasing(lisPadre[i], A);
}
int lis(vector<int> &A) {
  int tam = (int)(A).size();
  LIS.assign(tam, 0);
  lisPadre.assign(tam, -1);
  lisDP.assign(tam, INF);
  int M = 0;
  for (int i = (0); i < (tam); i++) {
    int j =
        upper_bound(lisDP.begin(), lisDP.begin() + M + 1, A[i]) - lisDP.begin();
    lisDP[j] = A[i];
    LIS[i] = j + 1;
    lisPadre[i] = (j == 0 ? -1 : LIS[j - 1]);
    M = max(M, j);
  }
  int maxv = 0;
  int maxi = 0;
  for (int i = tam - 1; i >= 0; i--) {
    if (LIS[i] > maxv) {
      maxv = LIS[i];
      maxi = i;
    }
  }
  return maxv;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> diffarray(m + 1, 0);
  for (int i = (0); i < (n); i++) {
    int a, b;
    cin >> a >> b;
    diffarray[a - 1]++;
    diffarray[b]--;
  }
  vector<int> cant(m, 0);
  for (int i = (0); i < (m); i++) {
    cant[i] = (i != 0 ? cant[i - 1] : 0) + diffarray[i];
  }
  int lisc = lis(cant);
  vector<int> creciente = LIS;
  reverse(cant.begin(), cant.end());
  int lisd = lis(cant);
  vector<int> decreciente = LIS;
  reverse(decreciente.begin(), decreciente.end());
  int maxUnimodal = 0;
  for (int i = (0); i < (m); i++) {
    maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i] - 1);
  }
  cout << maxUnimodal << "\n";
}
