#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXT = 530000;
using lint = long long;
using pi = pair<int, int>;
const int mod = 1e9 + 7;
int n, m;
pi a[MAXN];
struct seg {
  int tree[MAXT], lazy[MAXT];
  void lazydown(int p) {
    tree[2 * p] += lazy[p];
    tree[2 * p + 1] += lazy[p];
    lazy[2 * p] += lazy[p];
    lazy[2 * p + 1] += lazy[p];
    lazy[p] = 0;
  }
  void init(int s, int e, int p) {
    if (s == e) {
      tree[p] = s;
      return;
    }
    int m = (s + e) / 2;
    init(s, m, 2 * p);
    init(m + 1, e, 2 * p + 1);
    tree[p] = max(tree[2 * p], tree[2 * p + 1]);
  }
  void add(int s, int e, int ps, int pe, int p, int v) {
    if (e < ps || pe < s) return;
    if (s <= ps && pe <= e) {
      tree[p] += v;
      lazy[p] += v;
      return;
    }
    int pm = (ps + pe) / 2;
    lazydown(p);
    add(s, e, ps, pm, 2 * p, v);
    add(s, e, pm + 1, pe, 2 * p + 1, v);
    tree[p] = max(tree[2 * p], tree[2 * p + 1]);
  }
} seg;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
  }
  sort(a, a + n);
  seg.init(1, m + 1, 1);
  int mtch = 0;
  for (int i = 0; i < n; i++) {
    seg.add(1, a[i].second, 1, m + 1, 1, 1);
    if (seg.tree[1] > m + 1 + a[i].first) {
      seg.add(1, a[i].second, 1, m + 1, 1, -1);
    } else {
      mtch++;
    }
  }
  cout << n - mtch << endl;
}
