#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int n, m, tot, data[maxn];

struct node {
  int l, r;
  
  inline bool operator < (const node &o) const {
    return l < o.l || (l == o.l && r < o.r);
  }
} a[maxn];

priority_queue <int, vector <int>, greater <int> > Q;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].l, &a[i].r);
  }
  int L = 1, R = m;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    Q.push(a[i].r);
    if (L <= R && L <= a[i].l) {
      L++;
    } else {
      data[++tot] = Q.top(), Q.pop();
    }
  }
  int ans = 0;
  sort(data + 1, data + tot + 1);
  for (int i = tot; i; i--) {
    L <= R && R >= data[i] ? R-- : ans++;
  }
  printf("%d", ans);
  return 0;
}