#include <bits/stdc++.h>
using namespace std;
int read_p, read_ca, read_f;
inline int read() {
  read_p = 0;
  read_ca = getchar();
  read_f = 1;
  while (read_ca < '0' || read_ca > '9')
    read_f = read_ca == '-' ? -1 : read_f, read_ca = getchar();
  while (read_ca >= '0' && read_ca <= '9')
    read_p = read_p * 10 + read_ca - 48, read_ca = getchar();
  return read_p * read_f;
}
priority_queue<int, vector<int>, greater<int> > q;
struct na {
  int l, r;
} b[1000001];
bool operator<(na a, na b) { return a.l < b.l; }
int n, m, num = 0, mmh = 0, bo[1000001];
int main() {
  register int i, j;
  n = read();
  m = read();
  for (i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l || r != m + 1) b[++num].l = r, b[num].r = m + l;
  }
  sort(b + 1, b + 1 + num);
  for (i = 1, j = 1; i <= m + m; i++) {
    while (j <= num && b[j].l == i) q.push(b[j].r), j++;
    while (!q.empty() && q.top() < i) q.pop();
    if (!bo[i])
      if (!q.empty()) mmh++, q.pop(), bo[i + m] = 1;
  }
  printf("%d\n", n - mmh);
}
