#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long fastpo(long long a, long long x) {
  if (x == 0) return 1ll;
  if (x == 1) return a;
  long long y = fastpo(a, x / 2);
  if (x % 2 == 0) {
    return y * y;
  }
  return y * y * a;
}
long long inv(long long a, long long M) { return fastpo(a, M - 2); }
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return -1;
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> pre(m + 10, 0), seg(m + 10, 0);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    pre[l]++;
    pre[r + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    seg[i] += (seg[i - 1] + pre[i]);
  }
  multiset<int> s1, s2;
  vector<int> dp1(m + 10, 0), dp2(m + 10, 0);
  for (int i = 1; i <= m; i++) {
    s1.insert(seg[i]);
    auto it = s1.upper_bound(seg[i]);
    if (it != s1.end()) s1.erase(it);
    dp1[i] = s1.size();
  }
  for (int i = m; i >= 1; i--) {
    s2.insert(seg[i]);
    auto it = s2.upper_bound(seg[i]);
    if (it != s2.end()) s2.erase(it);
    dp2[i] = s2.size();
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, dp1[i] + dp2[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
