#include<bits/stdc++.h>

using namespace std;

typedef tuple< int, int, int > Pi;

int N, M, L[200000], R[200000];
int ans = 11451419;
Pi first[200000], second[200000];

int check(int vq)
{
  vector< Pi > que2;
  int tail = 1;
  bool used[200000] = {};
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(l, r, idx) = first[i];
    if(tail <= l && tail < vq) {
      tail++;
      used[idx] = true;
    }
  }
  int head = M;
  int ret = 0;
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(r, l, idx) = second[i];
    if(used[idx]) continue;
    r *= -1;
    if(r <= head && head >= tail) {
      head--;
    } else {
      ++ret;
    }
  }
  ans = min(ans, ret);
  return (ret);
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> L[i] >> R[i];
  for(int i = 0; i < N; i++) first[i] = make_tuple(L[i], -R[i], i);
  for(int i = 0; i < N; i++) second[i] = make_tuple(-R[i], L[i], i);
  sort(second, second + N);
  sort(first, first + N);


  int low = 1, high = M + 1;
  while(high - low > 1) {
    int mid = (low + high) >> 1;
    (check(mid) - check(mid - 1) > 0 ? low : high) = mid;
  }
  check(0);
  check(M + 1);
  for(int i = low - 30; i <= high + 30; i++)check(i);


  cout << ans << endl;
}
