#include <bits/stdc++.h>
using namespace std;
void Solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> B(2 * m + 1);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    cin >> l >> r;
    B[r].push_back({l + m, i});
  }
  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 || marked[i]) continue;
    while (!H.empty() && H.top().first < i) {
      H.pop();
    }
    if (!H.empty()) {
      ++placed;
      marked[i % m] = true;
      H.pop();
    }
  }
  cout << n - placed << "\n";
}
int main() {
  int tests = 1;
  for (; tests; --tests) {
    Solve();
  }
}
