#include <bits/stdc++.h>
using namespace std;
int l[200005], r[200005], n, m, now = 1;
struct sd {
  int x, y;
  bool operator<(const sd &fu) const { return x < fu.x; };
} in[200005];
int fl(int v) { return v == l[v] ? v : l[v] = fl(l[v]); }
int fr(int v) { return v == r[v] ? v : r[v] = fr(r[v]); }
int main() {
  scanf("%d%d", &n, &m);
  int ans = 0;
  for (int i = n; i; --i) scanf("%d%d", &in[i].x, &in[i].y);
  for (int i = 1; i <= m + 1; ++i) {
    l[i] = i;
    r[i] = i;
  }
  sort(in + 1, in + 1 + n);
  for (int i = 1; i <= n; ++i) {
    while (l[now] != now) ++now;
    if (now <= in[i].x) {
      l[fl(now)]--;
      r[fr(now)]++;
    } else {
      int rr = fr(in[i].y);
      if (rr > m)
        ++ans;
      else {
        r[rr]++;
        l[fl(in[i].y)]--;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
