#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> sol(vector<int> a, int m) {
  vector<int> res, v;
  for (int i = 1; i <= m; i++) {
    int t = upper_bound(res.begin(), res.end(), a[i]) - res.begin();
    res.resize(max((int)res.size(), t + 1));
    res[t] = a[i];
    v.push_back(t + 1);
  }
  ans = max(ans, (int)res.size());
  return v;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(m + 2);
  for (int i = 0; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u]++, a[v + 1]--;
  }
  for (int i = 2; i <= m; i++) a[i] += a[i - 1];
  auto u = sol(a, m);
  reverse(a.begin(), a.end());
  auto v = sol(a, m);
  reverse(v.begin(), v.end());
  for (int i = 0; i < m; i++) ans = max(ans, u[i] + v[i] - 1);
  printf("%d\n", ans);
}
