#include <bits/stdc++.h>
using namespace std;
int freq[100005], n, enter[100005], m;
template <typename T>
class SegmentTree {
  vector<T> segtree;

 public:
  SegmentTree(int size) { segtree.resize(4 * size, 0); }
  void update(int u, int a, int b, int i, int j, T x) {
    if (j < a || i > b || a > b) return;
    if (j >= b && i <= a) {
      segtree[u] = x;
      return;
    }
    update(u * 2, a, (a + b) / 2, i, j, x);
    update(u * 2 + 1, (a + b) / 2 + 1, b, i, j, x);
    segtree[u] = max(segtree[u * 2], segtree[u * 2 + 1]);
  }
  void update(int i, T x) { update(1, 0, segtree.size() / 4 - 1, i, i, x); }
  void update(int i, int j, T x) {
    update(1, 0, segtree.size() / 4 - 1, i, j, x);
  }
  T query(int u, int a, int b, int i, int j) {
    if (j < a || i > b || a > b) return 0;
    if (j >= b && i <= a) return segtree[u];
    return max(query(u * 2, a, (a + b) / 2, i, j),
               query(u * 2 + 1, 1 + (a + b) / 2, b, i, j));
  }
  T query(int i, int j) { return query(1, 0, segtree.size() / 4 - 1, i, j); }
};
int dpi[100005], dpd[100005];
int solve(int n) {
  fill_n(dpi, n, 0);
  fill_n(dpd, n, 0);
  SegmentTree<int> inc(100005), dec(100005);
  for (int i = 0; i < n; ++i) {
    inc.update(freq[i], inc.query(0, freq[i]) + 1);
    dpi[i] = inc.query(0, 100004);
  }
  reverse(freq, freq + n);
  for (int i = 0; i < n; ++i) {
    dec.update(freq[i], dec.query(0, freq[i]) + 1);
    dpd[i] = dec.query(0, 100004);
  }
  reverse(dpd, dpd + n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, dpi[i] + dpd[i] - 1);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = n, x, y; i--; ++enter[x], --enter[y + 1]) cin >> x >> y;
  for (int i = 1, run = 0; i <= m; ++i) freq[i - 1] = (run += enter[i]);
  cout << solve(m);
}
