#include <bits/stdc++.h>
using namespace std;
template <typename T>
using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
bool debug = 0;
template <typename T>
void DEBUG(const T& x) {
  if (debug) cerr << x;
}
template <typename T, typename... Args>
void DEBUG(const T& head, const Args&... tail) {
  if (debug) {
    cerr << head;
    DEBUG(tail...);
  }
}
const int N = 100000 + 5;
const int INF = 1 << 30;
class BIT {
 private:
  int n;
  vector<int> arr;
  inline int lowbit(int x) { return x & (-x); }

 public:
  void init(int n_) {
    n = n_;
    arr.clear();
    arr.resize(n);
    fill(begin(arr), end(arr), 0);
  }
  int query(int p) {
    int ret = 0;
    while (p) {
      ret = max(ret, arr[p]);
      p -= lowbit(p);
    }
    return ret;
  }
  void modify(int p, int x) {
    while (p < n) {
      arr[p] = max(arr[p], x);
      p += lowbit(p);
    }
  }
} bit;
class LiSan {
 private:
  vector<int> vv;

 public:
  void init() { vv.clear(); }
  void insert(int x) { vv.push_back(x); }
  void done() {
    sort(begin(vv), end(vv));
    vv.resize(distance(vv.begin(), unique(begin(vv), end(vv))));
  }
  int size() { return (int)(vv.size()); }
  int get(int x) {
    return distance(vv.begin(), lower_bound(begin(vv), end(vv), x)) + 1;
  }
} lisan;
int arr[N], lis[N], rlis[N];
int main(int argc, char* argv[]) {
  if (argc > 1 and string(argv[1]) == "-D") debug = 1;
  if (!debug) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    arr[l]++;
    arr[r + 1]--;
  }
  lisan.insert(-1);
  for (int i = 1; i <= m; i++) {
    arr[i] += arr[i - 1];
    lisan.insert(arr[i]);
  }
  lisan.insert(INF);
  lisan.done();
  bit.init(lisan.size() + 5);
  for (int i = 1; i <= m; i++) {
    int pre = bit.query(lisan.get(arr[i])) + 1;
    bit.modify(lisan.get(arr[i]), pre);
    lis[i] = bit.query(lisan.get(INF));
  }
  bit.init(lisan.size() + 5);
  for (int i = m; i >= 1; i--) {
    int pre = bit.query(lisan.get(arr[i])) + 1;
    bit.modify(lisan.get(arr[i]), pre);
    rlis[i] = bit.query(lisan.get(INF));
  }
  int ans = 0;
  for (int i = 0; i <= m; i++) ans = max(ans, lis[i] + rlis[i + 1]);
  cout << ans << '\n';
  return 0;
}
