#include <bits/stdc++.h>
using namespace std;
int L, R, n, m;
priority_queue<int> q;
struct nod {
  int l, r;
  friend bool operator<(nod a, nod b) {
    if (a.l != b.l) return a.l < b.l;
    return a.r > b.r;
  }
} a[100005];
int main() {
  scanf("%d%d", &n, &m);
  R = m + 1;
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].l, &a[i].r);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    if (a[i].l > L && L < m)
      L++;
    else
      q.push(a[i].r);
  while (!q.empty()) {
    if (R - L == 1) break;
    int x = q.top();
    q.pop();
    if (R > x) R--;
  }
  printf("%d\n", n - (L + (m - R + 1)));
}
