#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> seg;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    seg.emplace_back(l, r);
  }
  auto brute = [&]() {
    int res = 0;
    for (int mask = 0; mask < (1 << N); mask++) {
      int l = 0, r = 0, cnt = 0;
      for (int i = 0; i < N; i++) {
        if (mask & (1 << i)) {
          cnt++;
          l = max(l, seg[i].first);
          r = max(r, M + 1 - seg[i].second);
        }
      }
      res = max(res, cnt - min(l + r, M));
    }
    return res;
  };
  sort(begin(seg), end(seg), [&](pair<int, int> &a, pair<int, int> &b) {
    return a.second > b.second;
  });
  int ans = 0;
  multiset<int> L;
  for (int i = 0; i < N; i++) {
    int l = seg[i].first;
    int r = M + 1 - seg[i].second;
    int cnt = 1;
    ans = max(ans, cnt - min(l + r, M));
    for (auto &left : L) {
      cnt++;
      l = max(l, left);
      ans = max(ans, cnt - min(l + r, M));
    }
    L.emplace(seg[i].first);
  }
  cout << ans << "\n";
  return 0;
}
