#include <bits/stdc++.h>
using namespace std;
long long a[(2 * (1 << 18))];
long long laz[(2 * (1 << 18))];
int l[(2 * (1 << 18))];
int r[(2 * (1 << 18))];
void init(void) {
  for (int i = 0; i < int((1 << 18)); i++) {
    a[i] = 0;
    laz[i] = 0;
  }
  l[1] = 0;
  r[1] = (1 << 18);
  for (int i = 1; i < (1 << 18); i++) {
    l[(2 * i)] = l[i];
    r[(2 * i)] = (l[i] + r[i]) / 2;
    l[(2 * i) + 1] = (l[i] + r[i]) / 2;
    r[(2 * i) + 1] = r[i];
  }
  return;
}
long long ranchange(int ll, int rr, int k, long long x) {
  long long vl, vr;
  if (rr <= l[k] || r[k] <= ll)
    return 1000000000;
  else if (ll <= l[k] && r[k] <= rr) {
    laz[k] += x;
    return (a[k] + laz[k]);
  } else {
    int mm = (l[k] + r[k]) / 2;
    if (l[k] < rr && ll < mm) {
      vl = ranchange(ll, rr, 2 * k, x);
    } else
      vl = 1000000000;
    if (mm < rr && ll < r[k]) {
      vr = ranchange(ll, rr, (2 * k) + 1, x);
    } else
      vr = 1000000000;
    a[k] = min(vl, vr);
    return min(vl, vr);
  }
}
long long min_search(int ll, int rr, int k) {
  if (laz[k] != 0) {
    a[k] += laz[k];
    int mm = (l[k] + r[k]) / 2;
    if (k < (1 << 18)) {
      laz[(2 * k)] += laz[k];
      laz[(2 * k) + 1] += laz[k];
    }
    laz[k] = 0;
  }
  long long vl, vr;
  if (rr <= l[k] || r[k] <= ll)
    return 1000000000;
  else if (ll <= l[k] && r[k] <= rr)
    return a[k];
  else {
    vl = min_search(ll, rr, 2 * k);
    vr = min_search(ll, rr, (2 * k) + 1);
    a[k] = min(a[(2 * k)], a[(2 * k) + 1]);
    return min(vl, vr);
  }
}
int main(void) {
  vector<pair<int, int> > v;
  priority_queue<int> pq1;
  priority_queue<int> pq2;
  int n, m;
  int x, y, nx, z;
  int ans = 0;
  long long k;
  init();
  scanf("%d %d", &n, &m);
  for (int i = 0; i < int(n); i++) {
    scanf("%d %d", &x, &y);
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < int(m); i++) {
    ranchange(i + 1, i + 2, 1, m - i);
  }
  nx = 0;
  for (int i = 0; i < int(n); i++) {
    x = v[i].first;
    y = v[i].second;
    pq1.push(-y);
    if (nx >= x) {
      z = -pq1.top();
      pq1.pop();
      pq2.push(z);
      ranchange(1, z + 1, 1, -1);
      k = min_search(1, m + 2, 1);
      if (k < 0) {
        ans++;
        z = pq2.top();
        pq2.pop();
        ranchange(1, z + 1, 1, 1);
        pq1.push(-z);
      }
    } else {
      nx++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
