#include <bits/stdc++.h>
using namespace std;
int arr[100005];
vector<int> lis;
int bin(int v) {
  int l = 0, h = lis.size() - 1, ret = 0;
  while (l <= h) {
    int mid = (l + h) / 2;
    if (lis[mid] > v) {
      ret = mid;
      h = mid - 1;
    } else
      l = mid + 1;
  }
  return ret;
}
int ls[100005], ds[100005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    arr[u]++;
    arr[v + 1]--;
  }
  int p = 0;
  for (int i = 1; i <= m; i++) {
    p += arr[i];
    arr[i] = p;
  }
  lis.push_back(arr[1]);
  int mx = 1;
  for (int i = 2; i <= m; i++) {
    if (arr[i] >= lis[lis.size() - 1]) {
      lis.push_back(arr[i]);
      ls[i] = lis.size();
    } else {
      int x = bin(arr[i]);
      lis[x] = arr[i];
      ls[i] = x + 1;
    }
  }
  lis.clear();
  lis.push_back(arr[m]);
  ls[1] = 1;
  ds[m] = 1;
  for (int i = m - 1; i >= 1; i--) {
    if (arr[i] >= lis[lis.size() - 1]) {
      lis.push_back(arr[i]);
      ds[i] = lis.size();
    } else {
      int x = bin(arr[i]);
      lis[x] = arr[i];
      ds[i] = x + 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    mx = max(mx, ls[i] + ds[i] - 1);
  }
  printf("%d\n", mx);
}
