#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0;
struct Point {
  int d, r, v;
  bool operator<(const Point &y) const {
    return (v > y.v) || (v == y.v && r > y.r);
  }
};
struct Po {
  int d, r;
};
vector<Po> a[200127];
bool b[200127];
priority_queue<Point> h;
int L[200127], R[200127];
int main() {
  scanf("%d%d", &n, &m);
  int i, x, y;
  for (i = 1; i <= n; i++) L[i] = m + 1, R[i] = m;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if (x) a[1].push_back((Po){i, x});
    if (y <= m) a[y].push_back((Po){i, m}), L[i] = y;
  }
  for (i = 1; i <= m; i++) {
    for (auto v : a[i])
      if (!b[v.d])
        h.push((Point){v.d, v.r, (v.r == m) ? m : (v.r + R[v.d] - L[v.d] + 1)});
    while (!h.empty() && h.top().r < i) h.pop();
    if (!h.empty()) {
      b[h.top().d] = 1;
      h.pop();
      ++ans;
    }
  }
  printf("%d", n - ans);
  return 0;
}
