#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n, m;
pair<int, int> a[maxn];
priority_queue<int, vector<int>, greater<int> > que;
vector<int> vec;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) a[i].first = read(), a[i].second = read();
  sort(a + 1, a + n + 1);
  int cur = 0;
  for (int i = 1; i <= n; ++i) {
    que.push(a[i].second);
    if (cur == a[i].first) {
      vec.push_back(que.top());
      que.pop();
    } else
      ++cur;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int now = m + 1;
  for (int i = 0; i < (int)vec.size(); ++i) {
    if (now == vec[i]) continue;
    --now;
  }
  printf("%d\n", n - m + now - cur - 1);
  return 0;
}
