#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, a, b;
  cin >> n >> m;
  vector<int> coo(m + 2, 0);
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    coo[a]++;
    coo[b + 1]--;
  }
  int val = 0;
  for (int i = 0; i <= m; i++) {
    val += coo[i];
    coo[i] = val;
  }
  int maxi = 0;
  vector<int> ult1(m + 1, -1), ult2(m + 1, -1), ct1(m + 2, 0), ct2(m + 2, 0);
  ct1[0] = -1;
  ct2[m] = -1;
  for (int i = 1; i <= m; i++) {
    int last = coo[i];
    int l = 0, r = maxi;
    for (int M = (l + r) / 2; l < r; M = (l + r) / 2) {
      if (ult1[M] > last)
        r = M;
      else
        l = M + 1;
    }
    if (l == maxi and ult1[l] <= last) {
      ult1[l + 1] = last;
      maxi = max(maxi, l + 1);
    } else {
      ult1[l] = last;
      maxi = max(maxi, l);
    }
    ct1[i] = maxi;
  }
  maxi = 0;
  for (int i = m; i > 0; i--) {
    int last = coo[i];
    int l = 0, r = maxi;
    for (int M = (l + r) / 2; l < r; M = (l + r) / 2) {
      if (ult2[M] > last)
        r = M;
      else
        l = M + 1;
    }
    if (l == maxi and ult2[l] <= last) {
      ult2[l + 1] = last;
      maxi = max(maxi, l + 1);
    } else {
      ult2[l] = last;
      maxi = max(maxi, l);
    }
    ct2[i] = maxi;
  }
  int ans = 0;
  for (int i = 1; i < m; i++) {
    ans = max(ans, ct1[i] + ct2[i + 1]);
  }
  ans = max(max(ans, ct1[m]), ct2[1]);
  cout << ans << "\n";
  return 0;
}
