#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[200010];
const int Z = (1 << 18);
int sum[Z * 2], pr[Z * 2];
void in(int x, int p) {
  x += Z;
  sum[x] += p;
  pr[x] = min(0, p);
  x /= 2;
  while (x) {
    sum[x] = sum[x * 2] + sum[x * 2 + 1];
    pr[x] = min(pr[x * 2], sum[x * 2] + pr[x * 2 + 1]);
    x /= 2;
  }
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &p[i].first, &p[i].second);
    p[i].second = -p[i].second;
  }
  sort(p, p + N);
  for (int i = 1; i <= M; i++) in(i, -1);
  for (int i = 0; i < N; i++) {
    p[i].second = -p[i].second;
  }
  int l = 0, r = 0;
  vector<int> u;
  for (int i = 0; i < N; i++) {
    if (p[i].first >= l + 1) {
      u.push_back(p[i].second);
      l++;
    } else {
      in(p[i].second, 1);
      while (M + pr[1] >= r + 1) r++;
    }
  }
  int ans = l + r;
  sort(u.rbegin(), u.rend());
  for (auto &x : u) {
    l--;
    in(x, 1);
    while (M + pr[1] >= r + 1) r++;
    ans = max(ans, l + r);
  }
  printf("%d\n", N - ans);
  return 0;
}
