#include <bits/stdc++.h>
using namespace std;
using Int = long long;
signed main() {
  Int n, m;
  cin >> n >> m;
  vector<Int> s(m + 2), t(m + 2);
  for (Int i = 0; i < n; i++) {
    Int l, r;
    cin >> l >> r;
    s[l]++;
    t[r]++;
  }
  for (Int i = 1; i <= m; i++) t[i] += t[i - 1];
  for (Int i = m; i >= 0; i--) s[i] += s[i + 1];
  vector<Int> c;
  for (Int i = 1; i <= m; i++) c.emplace_back(s[i] + t[i]);
  sort(c.rbegin(), c.rend());
  auto check = [&](Int x) -> Int {
    for (Int i = 0; i < x; i++)
      if (c[i] < x - i) return 0;
    return 1;
  };
  Int l = -1, r = n + 1;
  while (l + 1 < r) {
    Int m = (l + r) >> 1;
    if (check(m))
      l = m;
    else
      r = m;
  }
  cout << n - l << endl;
  return 0;
}
