#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <class T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return a;
}
const long long INF = 1e9 + 7;
const long long mod = 100000007;
const long long BIG_INF = 1e18 + 7;
const long long N = 1e6 + 7;
const long long T = 1 << 20;
const long double inf = 1e18;
long long n, m, k, q;
int tree[T * 2];
int tree2[T * 2];
int ros[N];
int mal[N];
void add1(int pocz, int kon) {
  pocz += T - 1;
  kon += T + 1;
  while (pocz / 2 != kon / 2) {
    if (pocz % 2 == 0) tree[pocz + 1]++;
    if (kon & 1) tree[kon - 1]++;
    pocz /= 2;
    kon /= 2;
  }
}
int ask1(int poz) {
  poz += T;
  int ret = 0;
  while (poz) {
    ret += tree[poz];
    poz /= 2;
  }
  return ret;
}
int ask2(int pocz, int kon) {
  pocz += T - 1;
  kon += T + 1;
  int ret = 0;
  while (pocz / 2 != kon / 2) {
    if (pocz % 2 == 0) ret = max(ret, tree2[pocz + 1]);
    if (kon & 1) ret = max(ret, tree2[kon - 1]);
    pocz /= 2;
    kon /= 2;
  }
  return ret;
}
void add2(int poz, int val) {
  poz += T;
  tree2[poz] = val;
  poz /= 2;
  while (poz) {
    tree2[poz] = max(tree2[poz + poz], tree2[poz + poz + 1]);
    poz /= 2;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  add1(1, m);
  for (int i = 0; i < (n); i++) {
    int a, b;
    cin >> a >> b;
    add1(a, b);
  }
  for (int i = 1; i <= m; i++) {
    ros[i] = ask2(1, ask1(i)) + 1;
    add2(ask1(i), ros[i]);
  }
  for (int i = 0; i < (T * 2); i++) tree2[i] = 0;
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    mal[i] = ask2(1, ask1(i)) + 1;
    add2(ask1(i), mal[i]);
    ans = max(ans, ros[i] + mal[i] - 1);
  }
  cout << ans << '\n';
}
