#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 = 1000005, Mo = 1000000007;
multiset<int> S;
vector<pair<int, int> > Q;
int n, m, q, a[MAXN], b[MAXN];
void build(int x, int l, int r) {
  if (l == r) {
    a[x] = 0;
    b[x] = l;
    return;
  }
  int mid = (l + r) / 2;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  b[x] = min(b[x << 1], b[x << 1 | 1]);
}
void pushdown(int x) {
  if (a[x]) {
    b[x << 1] -= a[x];
    b[x << 1 | 1] -= a[x];
    a[x << 1] += a[x];
    a[x << 1 | 1] += a[x];
    a[x] = 0;
  }
}
void change(int x, int l, int r, int k) {
  if (k <= l) {
    b[x]--, a[x]--;
    return;
  }
  int mid = (l + r) / 2;
  pushdown(x);
  if (k <= mid) change(x << 1, l, mid, k);
  if (k <= r) change(x << 1 | 1, mid + 1, r, k);
  b[x] = min(b[x << 1], b[x << 1 | 1]);
}
int query(int x, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  pushdown(x);
  if (b[x << 1 | 1] == 0)
    return query(x << 1 | 1, mid + 1, r);
  else
    return query(x << 1, l, mid);
}
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());
  int Qsize = Q.size(), tot1 = 0, tot2 = 0;
  S.clear();
  build(1, 0, m);
  for (int i = (0); i <= (Qsize - 1); ++i) {
    int x = Q[i].first, y = Q[i].second;
    if (tot1 < x && x <= m - tot2)
      tot1++, S.insert(y);
    else {
      S.insert(y);
      auto tmp = S.begin();
      int M = m + 1 - (*tmp);
      S.erase(tmp);
      if (query(1, 0, m) < M && tot2 < m - x) tot2++, change(1, 0, m, M);
    }
  }
  printf("%d\n", n - tot1 - tot2);
  return 0;
}
