#include <bits/stdc++.h>
using namespace std;
void _dbg(string) { cout << endl; }
template <class H, class... T>
void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(n), r(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> l[i] >> r[i];
  int ans = 1120000000;
  for (int _ = (int)(0); _ < (int)(2); _++) {
    vector<bool> occupied(m + 1, false);
    vector<bool> used(n, false);
    int cnt = 0;
    using P = pair<pair<int, int>, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    for (int i = (int)(0); i < (int)(n); i++) pq.push({{l[i], l[i]}, i});
    int cur = 1;
    while (!pq.empty()) {
      auto p = pq.top();
      pq.pop();
      if (p.first.second < cur) continue;
      occupied[cur] = true;
      used[p.second] = true;
      cur++;
      cnt++;
      if (cur > m) break;
    }
    while (!pq.empty()) pq.pop();
    for (int i = (int)(0); i < (int)(n); i++)
      if (!used[i]) pq.push({{m + 1 - r[i], r[i]}, i});
    cur = m;
    while (occupied[cur]) cur--;
    while (cur > 0 && !pq.empty()) {
      auto p = pq.top();
      pq.pop();
      if (p.first.second > cur) continue;
      occupied[cur] = true;
      used[p.second] = true;
      cur--;
      cnt++;
      while (occupied[cur]) cur--;
    }
    ans = min(ans, n - cnt);
    for (int i = (int)(0); i < (int)(n); i++) {
      swap(l[i], r[i]);
      l[i] = m + 1 - l[i];
      r[i] = m + 1 - r[i];
    }
  }
  cout << ans << endl;
  return 0;
}
