#include <bits/stdc++.h>
using namespace std;
inline void check_max(int a, int &b) {
  if (a > b) b = a;
}
priority_queue<int, vector<int>, greater<int>> Q;
const int N = 201000;
pair<int, int> s[N * 3];
int f[N * 2];
int n, m, tot, ans;
int main() {
  freopen("in", "r", stdin);
  scanf("%d%d", &n, &m);
  tot = 0;
  for (int i = 1, first, second; i <= n; i++) {
    scanf("%d%d", &first, &second);
    first += m;
    std::swap(first, second);
    if (first > second) continue;
    if (first <= 0) first = 1;
    s[++tot] = pair<int, int>(first, second);
    if (first + m > second)
      s[++tot] = pair<int, int>(first + m, std::min(second + m, m + m));
    if (second - m < first)
      s[++tot] = pair<int, int>(std::max(first - m, 1), second - m);
  }
  std::sort(s + 1, s + tot + 1);
  ans = 0;
  for (int i = 1, ind = 1, m2 = m * 2; i <= m2; i++) {
    while (s[ind].first <= i && ind <= tot) Q.push(s[ind].second), ind++;
    while (!Q.empty() && Q.top() < i) Q.pop();
    if (!Q.empty()) ans++, Q.pop();
    f[i] = ans;
  }
  ans = 0;
  for (int i = m, m2 = m * 2; i <= m2; i++) check_max(f[i] - f[i - m], ans);
  printf("%d\n", std::max(n - ans, 0));
  return 0;
}
