#include <bits/stdc++.h>
std::priority_queue<int> que;
std::vector<int> pos[200005];
int rem[200005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    pos[l].push_back(r);
  }
  int l = 0;
  for (int i = 0; i <= m; i++) {
    for (int x : pos[i]) {
      if (l < i) {
        que.push(x);
        l++;
        continue;
      }
      if (que.empty() || x <= que.top())
        rem[x]++;
      else {
        rem[que.top()]++;
        que.pop();
        que.push(x);
      }
    }
  }
  int r = m + 1, ans = rem[m + 1];
  for (int i = m; i; i--) {
    while (rem[i]) {
      if (i < r && l + 1 < r)
        r--;
      else
        ans++;
      rem[i]--;
    }
  }
  printf("%d\n", ans);
  return 0;
}
