#include <bits/stdc++.h>
const int INF = 1e9 + 7;
const double EPS = 1e-6;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2e5 + 9;
const int maxn = 1e5 + 100;
using namespace std;
inline void time() { cerr << (clock() * 1.0 / CLOCKS_PER_SEC * 1.0); }
int n, m, l, r, pr[maxn], res[maxn], d[maxn];
int main() {
  cin.tie(0);
  ios_base ::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    pr[l]++;
    pr[r + 1]--;
  }
  for (int i = 1; i <= m; i++) pr[i] += pr[i - 1];
  d[0] = -1e9;
  for (int i = 1; i <= m; i++) d[i] = 1e9;
  for (int i = 1; i <= m; i++) {
    int j = upper_bound(d, d + m + 1, pr[i]) - d;
    res[i] = j;
    d[j] = pr[i];
  }
  d[0] = -1e9;
  for (int i = 1; i <= m; i++) d[i] = 1e9;
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    int j = upper_bound(d, d + m + 1, pr[i]) - d;
    ans = max(ans, res[i] + j - 1);
    d[j] = pr[i];
  }
  cout << ans;
  return 0;
}
