#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int expo(long long int base, long long int exponent,
                   long long int mod) {
  long long int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
long long int n, m, a[200005], lft[200005], rgt[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1;
  while (tests--) {
    long long int i, j, k;
    cin >> n >> m;
    for (long long int i = 1; i <= n; i++) {
      cin >> j >> k;
      a[j]++;
      a[k + 1]--;
    }
    for (long long int i = 1; i <= m; i++) a[i] += a[i - 1];
    vector<long long int> v;
    for (long long int i = 1; i <= m; i++) {
      long long int tmp = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
      lft[i] = tmp + 1;
      if (tmp >= v.size())
        v.push_back(a[i]);
      else
        v[tmp] = a[i];
    }
    v.clear();
    for (i = m; i > 0; i--) {
      long long int tmp = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
      rgt[i] = tmp + 1;
      if (tmp >= v.size())
        v.push_back(a[i]);
      else
        v[tmp] = a[i];
    }
    long long int ans = 0;
    for (long long int i = 1; i <= m; i++) {
      ans = max(ans, rgt[i] + lft[i] - 1);
    }
    cout << ans;
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
