#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 19;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
vector<int> Vv[200050];
multiset<int> Mx;
vector<int> Vu;
long long getv(int a, int M) {
  int i;
  Mx.clear();
  Vu.clear();
  for (i = 1; i <= M; i++) {
    for (auto it : Vv[i]) Mx.insert(it);
    if (i >= M - a + 1) {
      if (Mx.empty()) return -LL_INF;
      Mx.erase(Mx.begin());
    }
  }
  for (auto it : Vv[M + 1]) Mx.insert(it);
  for (auto it : Mx) Vu.push_back(it);
  int st = 1, en = min((int)Vu.size(), M - a), mi, rv = 0;
  while (st <= en) {
    mi = (st + en) / 2;
    for (i = 0; i < mi; i++)
      if (Vu[Vu.size() - mi + i] < i + 1) break;
    if (i >= mi) {
      rv = mi;
      st = mi + 1;
    } else
      en = mi - 1;
  }
  return a + rv;
}
int main() {
  int N, M, i, j;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= N; i++) {
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    Vv[t2].push_back(t1);
  }
  int st = 0, en = min(N, M), mi;
  while (st < en) {
    int mi1 = (st + en) / 2;
    int mi2 = mi1 + 1;
    long long v1 = getv(mi1, M);
    long long v2 = getv(mi2, M);
    if (v1 >= v2)
      en = mi2 - 1;
    else
      st = mi1 + 1;
  }
  long long v = getv(st, M);
  return !printf("%lld\n", N - v);
}
