#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> pq, ot;
inline long long RD() {
  long long res;
  char cr;
  while ((cr = getchar()) < '0' || cr > '9')
    ;
  res = cr - '0';
  while ((cr = getchar()) >= '0' && cr <= '9') res = res * 10 + cr - '0';
  return res;
}
struct Team {
  int id, me;
  long long has, flo;
} team[300005];
bool cmp(Team a, Team b) {
  return a.has != b.has ? a.has > b.has : a.me > b.me;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    team[i].has = RD();
    team[i].flo = RD();
  }
  team[1].me = 1;
  std::sort(team + 1, team + 1 + n, cmp);
  int pos = 0;
  for (int i = 1; i <= n; i++)
    if (team[i].me) {
      pos = i;
      break;
    }
  for (int i = 1; i < pos; i++) pq.push((team[i].flo - team[i].has + 1) * (-1));
  int ans = pos;
  int nowpos = pos;
  int floated = 0;
  long long cangive = 0;
  long long nowhas = team[pos].has;
  for (int i = pos + 1; i <= n; i++) {
    if (team[i].has < team[i - 1].has) {
      for (int j = nowpos + 1; j < i; j++)
        pq.push((team[j].flo - team[j].has + 1) * (-1));
      nowpos = i - 1;
    }
    cangive += nowhas - team[i].has;
    nowhas = team[i].has;
    bool flag = 1;
    while (flag) {
      flag = 0;
      while (!pq.empty() && cangive >= pq.top() * (-1)) {
        flag = 1;
        cangive -= pq.top() * (-1);
        ot.push(pq.top() * (-1));
        pq.pop();
        floated++;
      }
      while (!ot.empty() && !pq.empty() && ot.top() > pq.top() * (-1)) {
        flag = 1;
        cangive += ot.top() - pq.top() * (-1);
        long long a1 = ot.top() * (-1);
        long long a2 = pq.top() * (-1);
        ot.pop();
        pq.pop();
        ot.push(a2);
        pq.push(a1);
      }
    }
    if (nowpos - floated < ans) ans = nowpos - floated;
  }
  for (int j = nowpos + 1; j <= n && team[j].has > 0; j++)
    pq.push((team[j].flo - team[j].has + 1) * (-1));
  if (team[n].has > 0) nowpos = n;
  cangive += nowhas;
  bool flag = 1;
  while (flag) {
    flag = 0;
    while (!pq.empty() && cangive >= pq.top() * (-1)) {
      flag = 1;
      cangive -= pq.top() * (-1);
      ot.push(pq.top() * (-1));
      pq.pop();
      floated++;
    }
    while (!ot.empty() && !pq.empty() && ot.top() > pq.top() * (-1)) {
      flag = 1;
      cangive += ot.top() - pq.top() * (-1);
      long long a1 = ot.top() * (-1);
      long long a2 = pq.top() * (-1);
      ot.pop();
      pq.pop();
      ot.push(a2);
      pq.push(a1);
    }
  }
  if (nowpos - floated < ans) ans = nowpos - floated;
  printf("%d", ans);
}
