#include <bits/stdc++.h>
using namespace std;
int a[100010];
int b[100010];
int cha[100010];
vector<int> lis;
int inc[100010];
int decr[100010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    cha[x]++;
    cha[y + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    a[i] = a[i - 1] + cha[i];
  }
  lis.push_back(-100);
  lis.push_back(a[1]);
  inc[1] = 1;
  for (int i = 2; i <= m; i++) {
    int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin();
    if (temp == lis.size()) lis.push_back(a[i]);
    inc[i] = temp;
    lis[temp] = a[i];
  }
  for (int i = m; i >= 1; i--) b[m + 1 - i] = a[i];
  for (int i = m; i >= 1; i--) a[i] = b[i];
  lis.clear();
  lis.push_back(-100);
  lis.push_back(a[1]);
  decr[1] = 1;
  for (int i = 2; i <= m; i++) {
    int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin();
    if (temp == lis.size()) lis.push_back(a[i]);
    decr[i] = temp;
    lis[temp] = a[i];
  }
  for (int i = 1; i <= m; i++) inc[i] += decr[m + 1 - i];
  cout << *max_element(inc + 1, inc + m + 1) - 1 << endl;
}
