#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> B;
int check(int postpone) {
  vector<bool> marked(m + 1);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      H;
  int placed = 0;
  for (int i = 0; i <= 2 * m; ++i) {
    for (auto el : B[i]) {
      H.push(el);
    }
    if (i == 0 || i <= postpone) continue;
    while (!H.empty() && H.top().first < i) {
      H.pop();
    }
    if (!H.empty()) {
      ++placed;
      marked[i % m] = true;
      H.pop();
    }
  }
  return placed;
}
void Solve() {
  cin >> n >> m;
  B = vector<vector<pair<int, int>>>(2 * m + 1);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    cin >> l >> r;
    B[r].push_back({l + m, i});
  }
  int lo = 0, hi = m + 1;
  while (hi - lo > 1) {
    int mid = (lo + hi) >> 1;
    if (check(mid) - check(mid - 1) < 0) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << n - check(lo) << "\n";
}
int main() {
  int tests = 1;
  for (; tests; --tests) {
    Solve();
  }
}
