#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17 + 9;
long long n, m;
vector<int> num;
long long dp[100009][2];
void solve(int tp) {
  multiset<int> s;
  multiset<int>::iterator it;
  if (tp == 0) {
    for (long long i = 1; i < (m + 1); ++i) {
      s.insert(num[i]);
      it = s.upper_bound(num[i]);
      if (it != s.end()) s.erase(it);
      dp[i][tp] = (long long)(s).size();
    }
  } else {
    for (long long i = m + 1 - 1; i >= 1; i--) {
      s.insert(num[i]);
      it = s.upper_bound(num[i]);
      if (it != s.end()) s.erase(it);
      dp[i][tp] = (long long)(s).size();
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  long long acum[100009];
  memset(acum, 0, sizeof acum);
  for (long long i = 0; i < (n); ++i) {
    long long a, b;
    cin >> a >> b;
    acum[a]++;
    acum[b + 1]--;
  }
  for (long long i = 1; i < (m + 2); ++i) {
    acum[i] += acum[i - 1];
  }
  for (long long i = 0; i < (m + 1); ++i) {
    num.push_back(acum[i]);
  }
  solve(0);
  solve(1);
  long long ans = 0;
  for (long long i = 1; i < (m + 1); ++i) {
    ans = max({dp[i][0] + dp[i][1] - 1, ans});
  }
  cout << ans << "\n";
  return 0;
}
