#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt[100100];
vector<pair<int, int> > chg;
int M[100100];
int linc[100100];
int ldec[100100];
void read() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int p, q;
    cin >> p >> q;
    chg.push_back(make_pair(p, 1));
    chg.push_back(make_pair(q + 1, -1));
  }
  sort(chg.begin(), chg.end());
  unsigned int ptr = 0;
  int cur = 0;
  for (int i = 1; i <= m; i++) {
    while (ptr < chg.size() && chg[ptr].first == i) {
      cur += chg[ptr].second;
      ptr++;
    }
    cnt[i] = cur;
  }
}
void solve(int* Linc) {
  for (int i = 0; i <= m; i++) M[i] = 0;
  cnt[0] = 0;
  int L = 0;
  for (int i = 1; i <= m; i++) {
    int a = 0, b = L;
    while (a < b) {
      int s = (a + b + 1) / 2;
      if (cnt[M[s]] <= cnt[i])
        a = s;
      else
        b = s - 1;
    }
    M[a + 1] = i;
    if (a + 1 > L) L++;
    Linc[i] = L;
  }
}
void solve2() {
  solve(linc);
  reverse(cnt + 1, cnt + m + 1);
  solve(ldec);
  reverse(ldec + 1, ldec + m + 1);
  int ans = 0;
  linc[m + 1] = ldec[m + 1] = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, linc[i] + ldec[i + 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  read();
  solve2();
}
