#include <bits/stdc++.h>
using namespace std;
const int TAM = 1e5 + 100;
int n, m;
int flag[TAM];
int v[2][TAM];
int dp[2][TAM];
void f(int ix) {
  int a[TAM];
  memset(a, 0, sizeof a);
  int t = 1;
  dp[ix][1] = t;
  a[1] = v[ix][1];
  for (int i = 2; i <= m; i++) {
    int x = v[ix][i];
    if (x < a[1]) {
      a[1] = x;
      dp[ix][i] = 1;
    } else if (x >= a[t]) {
      t++;
      a[t] = x;
      dp[ix][i] = t;
    } else {
      int l = 1, h = t, me;
      while (h - l > 1) {
        me = l + (h - l) / 2;
        if (a[me] > x)
          h = me;
        else
          l = me;
      }
      if (a[l] > x)
        me = l;
      else
        me = h;
      a[me] = x;
      dp[ix][i] = me;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    flag[l]++;
    flag[r + 1]--;
  }
  int x = 0;
  for (int i = 1; i <= m; i++) {
    x += flag[i];
    v[0][i] = x;
    v[1][i] = x;
  }
  reverse(v[1] + 1, v[1] + 1 + m);
  f(0);
  f(1);
  reverse(dp[1] + 1, dp[1] + 1 + m);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, dp[0][i] + dp[1][i] - 1);
  }
  cout << ans << endl;
  return 0;
}
