#include <bits/stdc++.h>
using namespace std;
long long int n, m, pre[100005], res;
vector<long long int> func() {
  long long int res = 0;
  vector<long long int> dp(m, 0);
  set<pair<long long int, long long int> > s;
  for (long long int i = 0; i < m; i++) {
    auto it = s.upper_bound({pre[i], 100005});
    if (s.empty() || it == s.begin()) {
      dp[i] = 1;
      s.insert({pre[i], dp[i]});
      continue;
    }
    --it;
    dp[i] = it->second + 1;
    it = s.lower_bound({pre[i], 0});
    while (!s.empty() && it != s.end() && it->second <= dp[i]) {
      s.erase(it);
      it = s.lower_bound({pre[i], 0});
    }
    s.insert({pre[i], dp[i]});
    res = max(res, dp[i]);
  }
  return dp;
}
void solve() {
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    x--;
    y--;
    pre[x]++;
    pre[y + 1]--;
  }
  for (long long int i = 0; i <= m; i++) pre[i] += pre[i - 1];
  vector<long long int> v1 = func();
  for (long long int i = 0; i < m / 2; i++) swap(pre[i], pre[m - i - 1]);
  vector<long long int> v2 = func();
  reverse(v2.begin(), v2.end());
  for (long long int i = 0; i < m; i++) res = max(res, v1[i] + v2[i] - 1);
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) solve();
}
