#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 10;
long long ent[maxn], ext[maxn], a[maxn], dp[maxn], ans_min[maxn], ans_max[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, open, close;
  cin >> n >> m;
  long long cur = 0;
  for (int i = 0; i < n; i++) {
    cin >> open >> close;
    ent[open]++, ext[close + 1]++;
  }
  a[1] = ent[1];
  for (int i = 2; i <= m; i++) a[i] = a[i - 1] + ent[i] - ext[i];
  fill(dp, dp + m + 1, LLONG_MAX);
  dp[0] = 0;
  for (int i = 1; i <= m; i++) {
    long long x = upper_bound(dp, dp + m + 1, a[i]) - dp;
    dp[x] = a[i];
    cur = max(cur, x);
    ans_min[i] = cur;
  }
  cout << endl;
  reverse(a + 1, a + m + 1);
  fill(dp, dp + m + 1, LLONG_MAX);
  dp[0] = 0, cur = 0;
  for (int i = 1; i <= m; i++) {
    long long x = upper_bound(dp, dp + m + 1, a[i]) - dp;
    dp[x] = a[i];
    cur = max(cur, x);
    ans_max[i] = cur;
  }
  reverse(ans_max + 1, ans_max + m + 1);
  long long ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, ans_min[i] + ans_max[i] - 1);
  cout << ans << endl;
  return 0;
}
