#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct data {
  int l, r;
  bool operator<(const data& b) const { return l == b.l ? r > b.r : l < b.l; }
} x[N];
int a[N];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &x[i].l, &x[i].r);
  sort(x + 1, x + 1 + n);
  int cnt = 0;
  int l = 1;
  for (int i = 1; i <= n; i++) {
    if (x[i].l < l || l > m)
      a[++cnt] = x[i].r;
    else
      l++;
  }
  int ans = 0;
  sort(a + 1, a + cnt + 1, cmp);
  int r = m;
  for (int i = 1; i <= cnt; i++) {
    if (a[i] > r || r == l)
      ans++;
    else
      r--;
  }
  printf("%d\n", ans);
  return 0;
}
