#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
const int N = 200005;
int n, m;
pair<int, int> a[N];
int cnt = 0, b[N];
priority_queue<int> Q;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i].first = read(), a[i].second = read();
  sort(a + 1, a + n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    Q.push(-a[i].second);
    if ((int)Q.size() > a[i].first) b[++cnt] = -Q.top(), Q.pop();
  }
  ans = Q.size();
  sort(b + 1, b + cnt + 1);
  int L = ans, R = m;
  for (int i = cnt; i >= 1; i--) {
    if (R >= b[i]) R--;
    if (L == R) break;
  }
  ans += m - R;
  printf("%d\n", n - ans);
  return 0;
}
