#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long n, m, mx, cr, ans;
pair<long long, long long> a[200005];
vector<long long> s[200005];
priority_queue<long long> pq, pp;
struct segtree {
  long long val[888888], lazy[888888];
  void lazydown(long long P) {
    val[2 * P] += lazy[P];
    lazy[2 * P] += lazy[P];
    val[2 * P + 1] += lazy[P];
    lazy[2 * P + 1] += lazy[P];
    lazy[P] = 0;
  }
  void upd(long long S, long long E, long long first, long long L = 1,
           long long R = m, long long P = 1) {
    if (S <= L && R <= E) {
      val[P] += first;
      lazy[P] += first;
      return;
    }
    if (E < L || R < S) return;
    lazydown(P);
    long long M = (L + R) / 2;
    upd(S, E, first, L, M, 2 * P);
    upd(S, E, first, M + 1, R, 2 * P + 1);
    val[P] = min(val[2 * P], val[2 * P + 1]);
  }
  long long qry(long long S, long long E, long long L = 1, long long R = m,
                long long P = 1) {
    if (S <= L && R <= E) return val[P];
    if (E < L || R < S) return inf;
    lazydown(P);
    long long M = (L + R) / 2;
    return min(qry(S, E, L, M, 2 * P), qry(S, E, M + 1, R, 2 * P + 1));
  }
} seg;
bool can(long long first) { return (seg.qry(m - first + 1, m) >= first - m); }
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) seg.upd(i, i, -i);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &a[i].first, &a[i].second);
    pq.push(-a[i].first);
    seg.upd(a[i].second, m, 1);
  }
  sort(a + 1, a + 1 + n);
  while (!pq.empty()) {
    long long T = -pq.top();
    pq.pop();
    if (T >= (1 + mx)) mx++;
  }
  for (long long i = mx, j = n; i >= 1; i--) {
    for (; j >= 1 && a[j].first >= mx; j--) {
      pq.push(a[j].second);
    }
    long long V = pq.top();
    seg.upd(V, m, -1);
    pp.push(-V);
    pq.pop();
  }
  for (long long i = mx; i >= 1; i--) {
    while (i + cr < m && can(cr + 1)) cr++;
    ans = max(ans, i + cr);
    seg.upd(-pq.top(), m, 1);
    pq.pop();
  }
  while (cr < m && can(cr + 1)) cr++;
  ans = max(ans, cr);
  printf("%lld\n", n - ans);
}
