#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 0x3f3f3f3f;
struct SegmentTree {
  int m_left, m_right;
  vector<int> m_v;
  explicit SegmentTree(int left, int right)
      : m_left(left), m_right(right), m_v(right - left + 1, 0) {}
  void insert(int y) { ++m_v[y - m_left]; }
  int query() {
    int sum = 0, ans = -INF;
    for (int i = m_right; i >= m_left; --i) {
      sum += m_v[i - m_left];
      ans = max(ans, sum - (m_right - i));
    }
    return ans;
  }
};
struct Wish {
  int l, r;
} wishes[200000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> wishes[i].l >> wishes[i].r;
  sort(wishes, wishes + n,
       [](const Wish &x, const Wish &y) { return x.l < y.l; });
  int ans = max(n - m, 0);
  SegmentTree sgt(0, m + 1);
  for (int i = 0, j = 0; i <= m + 1; ++i) {
    for (; j < n && wishes[j].l == i; ++j) sgt.insert(wishes[j].r);
    ans = max(ans, sgt.query() - i);
  }
  cout << ans << endl;
  return 0;
}
