#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> ev[402020];
int did[402020];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  int ret = 0;
  cin >> N >> M;
  for (i = 0; i < (N); i++) {
    cin >> x >> y;
    x += M;
    x--;
    y--;
    if (y <= x) ev[y].push_back(x);
  }
  multiset<int> ed;
  for (i = 0; i < (2 * M); i++) {
    while (ed.size() && *ed.begin() < i) ed.erase(ed.begin());
    for (auto& e : ev[i]) ed.insert(e);
    if (i) did[i] = did[i - 1];
    if (ed.size()) {
      did[i]++;
      ed.erase(ed.begin());
    }
  }
  int ma = 0;
  for (i = 0; i < (M + 10); i++) ma = max(ma, did[i + M] - did[i]);
  cout << N - ma << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
