#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, c[N];
int cnt[N];
int dp[N][2], len;
vector<int> f, g;
void add(int x, int y) {
  for (; x <= m; x += (x & (-x))) c[x] += y;
}
int ask(int x) {
  int ans = 0;
  for (; x; x -= (x & (-x))) ans += c[x];
  return ans;
}
int main() {
  int x, y;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, 1);
    add(y + 1, -1);
  }
  for (int i = 1; i <= m; ++i) cnt[i] = ask(i);
  f.clear();
  f.push_back(cnt[1]);
  dp[1][0] = 1;
  len = 0;
  for (int i = 2; i <= m; ++i) {
    if (cnt[i] >= f[len]) {
      f.push_back(cnt[i]);
      len++;
      dp[i][0] = len + 1;
    } else {
      int tmp = upper_bound(f.begin(), f.end(), cnt[i]) - f.begin();
      f[tmp] = cnt[i];
      dp[i][0] = tmp + 1;
    }
  }
  f.clear();
  f.push_back(cnt[m]);
  dp[m][1] = 1;
  len = 0;
  for (int i = m - 1; i; --i) {
    if (cnt[i] >= f[len]) {
      f.push_back(cnt[i]);
      len++;
      dp[i][1] = len + 1;
    } else {
      int tmp = upper_bound(f.begin(), f.end(), cnt[i]) - f.begin();
      f[tmp] = cnt[i];
      dp[i][1] = tmp + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = max(ans, dp[i][0] + dp[i][1] - 1);
  printf("%d\n", ans);
  return 0;
}
