#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, int>> P(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &P[i].first, &P[i].second);
  }
  sort(P.begin(), P.end());
  int bestL = 0;
  for (int i = 0; i < n; ++i) {
    if (P[i].first > bestL) ++bestL;
  }
  reverse(P.begin(), P.end());
  multiset<int> RS;
  int j = 0;
  for (int i = bestL; i >= 1; --i) {
    while (j < n && P[j].first >= i) {
      RS.insert(P[j].second);
      ++j;
    }
    assert(!RS.empty());
    RS.erase(prev(RS.end()));
  }
  while (j < n) {
    RS.insert(P[j].second);
    ++j;
  }
  int bestR = 0;
  for (auto it = RS.rbegin(); it != RS.rend(); ++it) {
    if (m + 1 - *it > bestR) ++bestR;
  }
  if (false)
    cerr << "bestL"
         << "=" << bestL << ","
         << "bestR"
         << "=" << bestR << endl;
  if (false)
    cerr << "RS"
         << "=";
  for (auto _x : RS)
    if (false) cerr << _x << ", ";
  if (false) cerr << endl;
  int ans = bestL + bestR;
  printf("%d\n", n - ans);
}
