#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, s = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') s = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return s * x;
}
const int MAXN = 400005, Mo = 1000000007;
int f[MAXN];
void add(int x, int y) {
  for (; x < MAXN; x += ((x) & (-(x)))) f[x] += y;
}
int sum(int x) {
  int y = 0;
  for (; x; x -= ((x) & (-(x)))) y += f[x];
  return y;
}
multiset<int> S;
vector<pair<int, int> > Q;
int n, m, q, a[MAXN], b[MAXN];
int main() {
  n = read();
  m = read();
  for (int i = (1); i <= (n); ++i) {
    int x = read(), y = read();
    Q.push_back(make_pair(x, y));
  }
  sort(Q.begin(), Q.end());
  memset(f, 0, sizeof(f));
  int Qsize = Q.size(), tot1 = 0, tot2 = 0, pos = 0;
  S.clear();
  for (int i = (0); i <= (Qsize - 1); ++i) {
    int x = Q[i].first, y = Q[i].second;
    if (tot1 < x)
      tot1++, S.insert(y);
    else {
      S.insert(y);
      auto tmp = S.begin();
      int M = m + 1 - (*tmp);
      S.erase(tmp);
      if (M > pos) {
        tot2++, add(M, 1);
        if (sum(M) == M) pos = max(pos, M);
      }
      while (sum(pos + 1) == pos + 1) pos++;
    }
  }
  printf("%d\n", n - tot1 - tot2);
  return 0;
}
