#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int n, m, x, y;
int a[maxn], p[maxn];
int b[maxn];
int dp1[maxn], dp2[maxn];
vector<int> v;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    p[x]++;
    p[y + 1]--;
  }
  for (int i = 1; i <= m; i++) a[i] = a[i - 1] + p[i], b[m - i + 1] = a[i];
  for (int i = 1; i <= m; i++) {
    auto now = upper_bound((v).begin(), (v).end(), a[i]);
    if (now == v.end())
      v.push_back(a[i]);
    else
      v[now - v.begin()] = a[i];
    dp1[i] = ((int)(v).size());
  }
  v.clear();
  for (int i = 1; i <= m; i++) {
    auto now = upper_bound((v).begin(), (v).end(), b[i]);
    if (now == v.end())
      v.push_back(b[i]);
    else
      v[now - v.begin()] = b[i];
    dp2[i] = ((int)(v).size());
  }
  int ans = 0;
  for (int i = 0; i <= m; i++) ans = max(ans, dp1[i] + dp2[m - i]);
  cout << ans << '\n';
}
