#include <bits/stdc++.h>
using namespace std;
struct arr {
  int x, y;
} a[200006];
priority_queue<arr> Q;
int n, m, t, x, y, ans, f[200006];
bool operator<(arr x, arr y) { return x.y < y.y; }
inline int read() {
  int x = 0, c = getchar(), f = 1LL;
  while (c < '0' || c > '9') f = (c == '-' ? -f : f), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1LL) + (x << 3) + c - 48, c = getchar();
  return f > 0 ? x : -x;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
bool cmp(arr x, arr y) { return x.x < y.x; }
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i].x = read(), a[i].y = read();
  sort(a + 1, a + n + 1, cmp);
  t = n;
  for (int i = m; i >= 1; i--) {
    while (a[t].x == i) Q.push(a[t]), t--;
    if (!Q.empty()) Q.pop(), f[i] = 1;
  }
  while (a[t].x == 0 && t) Q.push(a[t]), t--;
  t = m;
  while (!Q.empty()) {
    arr tmp = Q.top();
    Q.pop();
    while (f[t] == 1) t--;
    if (t < tmp.y)
      ans++;
    else
      f[t] = 1;
  }
  print(ans);
  puts("");
}
