#include <bits/stdc++.h>
using namespace std;
int N, M;
const int maxn = 2e5 + 5;
int L[maxn], R[maxn];
int p[maxn], s[maxn];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &L[i], &R[i]);
    R[i] = M + 1 - R[i];
  }
  priority_queue<int, vector<int>, greater<int> > pre, suf;
  for (int i = 1; i <= N; i++) {
    pre.push(L[i]);
    suf.push(R[i]);
  }
  p[0] = s[0] = 0;
  for (int i = 1; i <= M; i++) {
    while (!pre.empty() and pre.top() < i) {
      pre.pop();
    }
    if (!pre.empty()) {
      p[i] = p[i - 1] + 1;
      pre.pop();
    } else {
      p[i] = p[i - 1];
    }
    while (!suf.empty() and suf.top() < i) {
      suf.pop();
    }
    if (!suf.empty()) {
      s[i] = s[i - 1] + 1;
      suf.pop();
    } else {
      s[i] = s[i - 1];
    }
  }
  int ans = 0;
  for (int i = 0; i <= M; i++) {
    ans = max(ans, p[i] + s[M - i]);
  }
  cout << N - ans << endl;
  return 0;
}
