#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int> a) {
  int n = (int)a.size();
  vector<int> dp(n + 1, 1e9);
  dp[0] = -1e9;
  vector<int> ret(n);
  for (int i = 0; i < n; i++) {
    int x = (int)(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
    ret[i] = x;
    dp[x] = a[i];
  }
  return ret;
}
int main() {
  int n, m;
  cin >> m >> n;
  vector<int> a(n);
  vector<int> delta(n + 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    delta[x]++;
    delta[y]--;
  }
  int temp = 0;
  for (int i = 0; i < n; i++) {
    temp += delta[i];
    a[i] = temp;
  }
  auto l = solve(a);
  reverse(a.begin(), a.end());
  auto r = solve(a);
  reverse(r.begin(), r.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, l[i] + r[i] - 1);
  }
  cout << ans;
  return 0;
}
