#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 1e5 + 5;
int n, m, a[N], v[N], ve[N];
int res[2][N];
void go(int id) {
  memset(ve, INF, sizeof ve);
  for (int i = 1; i <= m; i++) {
    int j = lower_bound(ve, ve + N, v[i] + 1) - ve;
    ve[j] = v[i];
    res[id][i] = j;
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  int at = 0;
  for (int i = 1; i <= m; i++) {
    at += a[i];
    v[i] = at;
  }
  go(0);
  reverse(v + 1, v + m + 1);
  go(1);
  reverse(res[1] + 1, res[1] + m + 1);
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, res[0][i] + res[1][i] + 1);
  cout << ans << endl;
  return 0;
}
