#include <bits/stdc++.h>
using namespace std;
struct str {
  int l, r;
};
str arr[200010];
vector<int> lis[200010];
int sum[200010];
int main() {
  int n, m, i;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d%d", &arr[i].l, &arr[i].r);
  for (i = 0; i < n; i++) lis[arr[i].l].push_back(arr[i].r);
  int s = 0;
  int g = m;
  while (s < g) {
    int x = (s + g + 1) / 2;
    int cnt = 0;
    bool ok = 1;
    for (i = x; i >= 1; i--) {
      cnt += lis[i].size();
      if (cnt == 0) {
        ok = 0;
        break;
      }
      cnt--;
    }
    if (ok)
      s = x;
    else
      g = x - 1;
  }
  priority_queue<int> pq;
  for (i = m; i > s; i--)
    for (int x : lis[i]) pq.push(x);
  for (i = s; i >= 1; i--) {
    for (int x : lis[i]) pq.push(x);
    assert(!pq.empty());
    pq.pop();
  }
  for (int x : lis[0]) pq.push(x);
  int res = s;
  for (i = m; i > s; i--) {
    while (!pq.empty() && pq.top() > i) pq.pop();
    if (pq.empty()) break;
    pq.pop();
    res++;
  }
  res = n - res;
  printf("%d\n", res);
  return 0;
}
