#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> a[200010];
priority_queue<int> S1, S2;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    a[i].second = -a[i].second;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) a[i].second = -a[i].second;
  int now = 1;
  int ans = 0;
  while (now <= n && a[now].first == 0) S2.push(-a[now++].second);
  for (int i = 1; i <= m; i++) {
    if (now <= n) {
      ans++;
      S1.push(-a[now++].second);
      while (now <= n && a[now].first == i) {
        if (a[now].second > -S1.top()) {
          S2.push(-S1.top());
          S1.pop();
          S1.push(-a[now].second);
        } else
          S2.push(-a[now].second);
        now++;
      }
    } else {
      if (!S2.empty() && -S2.top() <= i) {
        S2.pop();
        ans++;
      }
    }
  }
  printf("%d\n", n - ans);
  return 0;
}
