#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Print() { cout << endl; }
template <typename T1, typename... T>
void Print(const T1 &t1, const T &...t) {
  cout << t1 << " ";
  Print(t...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class Iterator>
ostream &output_cantainer(ostream &os, Iterator first, Iterator last,
                          bool space = true) {
  if (space) {
    for (Iterator it = first; it != last; it++) {
      os << (*it) << ' ';
    }
    os << endl;
  } else
    for (Iterator it = first; it != last; it++) {
      os << (*it) << endl;
    }
  return os;
}
struct BigInt {
  static const int base = 1e9;
  static const int base_digits = 9;
  vector<int> z;
  int sign;
  BigInt() : sign(1) {}
  BigInt(long long v) : sign(1) {
    if (v < 0) sign = -1, v = -v;
    for (; v > 0; v = v / base) z.push_back(v % base);
  }
  BigInt(const string &s) { read(s); }
  BigInt(const BigInt &rhs) : z(rhs.z), sign(rhs.sign) {}
  friend void swap(BigInt &lhs, BigInt &rhs) {
    lhs.z.swap(rhs.z);
    std::swap(lhs.sign, rhs.sign);
  }
  void read(const string &s) {
    sign = 1;
    z.clear();
    int pos = 0, l = s.size();
    while (pos < l && (s[pos] == '+' || s[pos] == '-')) {
      if (s[pos] == '-') sign = -sign;
      ++pos;
    }
    for (int i = l - 1; i >= pos; i -= base_digits) {
      int x = 0;
      for (int j = max(pos, i - base_digits + 1); j <= i; j++) {
        x = x * 10 + s[j] - '0';
      }
      z.push_back(x);
    }
    trim();
  }
  BigInt &operator=(BigInt rhs) {
    swap(*this, rhs);
    return *this;
  }
  BigInt &operator=(long long v) {
    BigInt rhs(v);
    swap(*this, rhs);
    return *this;
  }
  BigInt operator+(const BigInt &rhs) {
    BigInt res(*this);
    res += rhs;
    return res;
  }
  BigInt &operator+=(const BigInt &rhs) {
    if (sign == rhs.sign) {
      for (int i = 0, carry = 0, u = max(z.size(), rhs.z.size());
           i < u || carry; i++) {
        if (i == z.size()) z.push_back(0);
        z[i] += carry + (i < (int)rhs.z.size() ? rhs.z[i] : 0);
        carry = z[i] >= base;
        if (carry) z[i] -= base;
      }
      return *this;
    }
    return (*this -= (-rhs));
  }
  BigInt operator-() const {
    BigInt res(*this);
    res.sign = -res.sign;
    return res;
  }
  BigInt operator-(const BigInt &rhs) const {
    BigInt res(*this);
    res -= rhs;
    return res;
  }
  BigInt &operator-=(const BigInt &rhs) {
    if (sign == rhs.sign) {
      if (abs() >= rhs.abs()) {
        for (int i = 0, carry = 0; i < (int)rhs.z.size() || carry; ++i) {
          z[i] -= carry + (i < (int)rhs.z.size() ? rhs.z[i] : 0);
          carry = z[i] < 0;
          if (carry) z[i] += base;
        }
        trim();
        return *this;
      }
      BigInt target(rhs - *this);
      target.neg();
      swap(*this, target);
      return *this;
    }
    return *this += (-rhs);
  }
  bool operator<(const BigInt &rhs) const {
    if (sign != rhs.sign) return sign < rhs.sign;
    if (z.size() != rhs.z.size())
      return (int)z.size() * sign < (int)rhs.z.size() * rhs.sign;
    for (int i = z.size() - 1; i >= 0; i--)
      if (z[i] != rhs.z[i]) return z[i] * sign < rhs.z[i] * sign;
    return false;
  }
  bool operator<=(const BigInt &rhs) const { return !(rhs < *this); }
  bool operator>=(const BigInt &rhs) const { return !(*this < rhs); }
  void neg() { sign = -sign; }
  void trim() {
    while (!z.empty() && z.back() == 0) z.pop_back();
    if (z.empty()) sign = 1;
  }
  bool isZero() const { return z.empty() || (z.size() == 1 && !z[0]); }
  BigInt abs() const {
    BigInt res(*this);
    res.sign *= res.sign;
    return res;
  }
  friend ostream &operator<<(ostream &os, const BigInt &v) {
    if (v.sign == -1) os << '-';
    os << ((v.z.empty()) ? 0 : v.z.back());
    for (int i = (int)v.z.size() - 2; i >= 0; --i)
      os << setw(base_digits) << setfill('0') << v.z[i];
    return os;
  }
  friend istream &operator>>(istream &is, BigInt &v) {
    string s;
    is >> s;
    v.read(s);
    return is;
  }
};
const int N = 1e5 + 4, INF = 1e8;
int n, m, c[N];
int dp1[N], dp2[N], p[N];
int v1[N], v2[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    p[u]++;
    p[v + 1]--;
  }
  for (int i = 1; i <= m; i++) c[i] = c[i - 1] + p[i];
  int ans = 0, len = 0;
  fill(dp1, dp1 + m + 1, INF);
  dp1[0] = -1;
  for (int i = 1; i <= m; i++) {
    int pos = upper_bound(dp1, dp1 + len + 1, c[i]) - dp1;
    v1[i] = pos;
    dp1[pos] = c[i];
    len = max(len, pos);
  }
  fill(dp2, dp2 + m + 1, INF);
  dp2[0] = -1;
  len = 0;
  for (int i = m; i >= 1; i--) {
    int pos = upper_bound(dp2, dp2 + len + 1, c[i]) - dp2;
    v2[i] = pos;
    dp2[pos] = c[i];
    len = max(len, pos);
  }
  for (int i = 1; i <= m; i++) ans = max(ans, v1[i] + v2[i] - 1);
  printf("%d\n", ans);
}
