#include <bits/stdc++.h>
using namespace std;
int read_p, read_ca;
inline int read() {
  read_p = 0;
  read_ca = getchar();
  while (read_ca < '0' || read_ca > '9') read_ca = getchar();
  while (read_ca >= '0' && read_ca <= '9')
    read_p = read_p * 10 + read_ca - 48, read_ca = getchar();
  return read_p;
}
struct na {
  int l, r;
} p[110000];
bool cmpl(na a, na b) { return a.l == b.l ? a.r > b.r : a.l < b.l; }
priority_queue<int, vector<int>, greater<int> > q, _q;
int n, m, mmh;
int main() {
  mmh = n = read();
  m = read();
  for (int i = 1; i <= n; i++) p[i].l = read(), p[i].r = read();
  sort(p + 1, p + 1 + n, cmpl);
  for (int i = 1; i <= n; i++)
    if (p[i].l == q.size())
      q.push(p[i].r), _q.push(q.top()), q.pop();
    else
      q.push(p[i].r), mmh--;
  for (int i = q.size() + 1; i <= m && !_q.empty(); i++)
    if (_q.top() <= i) _q.pop(), mmh--;
  printf("%d\n", mmh);
}
