#include <bits/stdc++.h>
using namespace std;

using P = pair<int, int>;

int n, m;
vector<P> v;
vector<int> r;
priority_queue<int, vector<int>, greater<int>> pq;

int solve();

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}
int solve() {
  int res = 0, cnt = 0, len = v.size();
  for (int i = 0; i < len; ++i) {
    pq.push(v[i].second);
    if (pq.size() > v[i].first) {
      r.push_back(pq.top());
      pq.pop();
    }
  }
  sort(r.begin(), r.end(), greater<int>());
  for (auto &p : r) p = m + 1 - p;
  len = r.size();
  for (int i = 0; i < len; ++i)
    if (++cnt > r[i]) ++res, --cnt;
  res += max((int)pq.size() + cnt - m, 0);
  return res;
}