One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there are seven teams with more balloons, you get the eight place. Ties are allowed.

You should know that it's important to eat before a contest. If the number of balloons of a team is greater than the weight of this team, the team starts to float in the air together with their workstation. They eventually touch the ceiling, what is strictly forbidden by the rules. The team is then disqualified and isn't considered in the standings.

A contest has just finished. There are n teams, numbered 1 through n. The i-th team has t_{i} balloons and weight w_{i}. It's guaranteed that t_{i} doesn't exceed w_{i} so nobody floats initially.

Limak is a member of the first team. He doesn't like cheating and he would never steal balloons from other teams. Instead, he can give his balloons away to other teams, possibly making them float. Limak can give away zero or more balloons of his team. Obviously, he can't give away more balloons than his team initially has.

What is the best place Limak can get?


-----Input-----

The first line of the standard input contains one integer n (2 ≤ n ≤ 300 000) — the number of teams.

The i-th of n following lines contains two integers t_{i} and w_{i} (0 ≤ t_{i} ≤ w_{i} ≤ 10^18) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.


-----Output-----

Print one integer denoting the best place Limak can get.


-----Examples-----
Input
8
20 1000
32 37
40 1000
45 50
16 16
16 16
14 1000
2 1000

Output
3

Input
7
4 4
4 4
4 4
4 4
4 4
4 4
5 5

Output
2

Input
7
14000000003 1000000000000000000
81000000000 88000000000
5000000000 7000000000
15000000000 39000000000
46000000000 51000000000
0 1000000000
0 0

Output
2



-----Note-----

In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is: Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak has only 14 balloons now and he would get the fifth place. Limak gives 6 balloons away to a team with 45 balloons. Now they have 51 balloons and weight 50 so they fly and get disqualified. Limak gives 1 balloon to each of two teams with 16 balloons initially. Limak has 20 - 6 - 6 - 1 - 1 = 6 balloons. There are three other teams left and their numbers of balloons are 40, 14 and 2. Limak gets the third place because there are two teams with more balloons. 

In the second sample, Limak has the second place and he can't improve it.

In the third sample, Limak has just enough balloons to get rid of teams 2, 3 and 5 (the teams with 81 000 000 000, 5 000 000 000 and 46 000 000 000 balloons respectively). With zero balloons left, he will get the second place (ex-aequo with team 6 and team 7).

Difficulty: MEDIUM_HARD
Tags: Data structures

Greedy algorithms
Skill types: Data structures

Greedy algorithms

Starter code:

Solutions:
from bisect import bisect_right
import heapq
n = int(input())
l = []
(ti, wi) = map(int, input().split())
bal = ti
pos = 1
for _ in range(n - 1):
	(ti, wi) = map(int, input().split())
	if ti > bal:
		pos += 1
	l.append((ti, wi - ti + 1))
l.sort()
best_pos = pos
op = bisect_right(l, (bal, float('inf')))
w = []
for (i, v) in l[op:]:
	heapq.heappush(w, v)
op -= 1
while w:
	head = heapq.heappop(w)
	if bal < head:
		break
	bal -= head
	pos -= 1
	while op >= 0 and l[op][0] > bal:
		heapq.heappush(w, l[op][1])
		op -= 1
		pos += 1
	best_pos = min(best_pos, pos)
print(best_pos)


from sys import stdin, stdout
from bisect import *
from heapq import *

def ri():
	return map(int, input().split())
n = int(input())
abw = [list(ri()) for i in range(n)]
a1 = abw[0][0]
a = [abw[i][0] for i in range(1, n)]
a.sort()
abw = abw[1:]
abw.sort(key=lambda e: e[0])
for j in range(len(abw)):
	if abw[j][0] > a1:
		break
else:
	j += 1
f = 0
mins = n - j
pq = [abw[i][1] - abw[i][0] for i in range(j, n - 1)]
heapify(pq)
iiprv = j
while len(pq) and a1 > 0:
	g = heappop(pq)
	if a1 > g:
		f += 1
		a1 -= g + 1
		ii = bisect(a, a1)
		for k in range(ii, iiprv):
			heappush(pq, abw[k][1] - abw[k][0])
		iiprv = ii
		mins = min(mins, n - ii - f)
print(mins)


import heapq
from bisect import bisect
inf = 10 ** 18 + 2

def rints():
	return list(map(int, input().split()))

def ri():
	return int(input())

def bin_search(arr, pred, lo=0, hi=None):
	if hi is None:
		hi = len(arr)
	while lo < hi:
		mid = (lo + hi) // 2
		if pred(arr[mid]):
			hi = mid
		else:
			lo = mid + 1
	return lo
n = ri()
(score, _) = rints()
teams = []
for _ in range(n - 1):
	(t, w) = rints()
	teams.append((w - t + 1, t, w))
teams.sort(key=lambda x: x[1])

def solve(score):
	idx = bin_search(teams, lambda x: x[1] > score)
	best = pos = len(teams) - idx + 1
	ahead = teams[idx:]
	behind = teams[:idx]
	heapq.heapify(ahead)
	while ahead and score >= ahead[0][0]:
		score -= heapq.heappop(ahead)[0]
		pos -= 1
		while behind and behind[-1][1] > score:
			heapq.heappush(ahead, behind.pop())
			pos += 1
		best = min(best, pos)
	return best
print(solve(score))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
(a, b) = map(int, input().split())
l = []
bal = []
rev = []
for i in range(1, n):
	(a1, b1) = map(int, input().split())
	if a1 > a:
		l.append((b1 - a1 + 1, a1, b1))
		bal.append(a1)
	else:
		rev.append((a1, b1))
bal.sort()
rev.sort(reverse=True)
heapq.heapify(l)
ans = len(bal) + 1
ma = ans
t = 0
f = 0
while a > 0:
	if len(l) == 0:
		break
	e = heapq.heappop(l)
	if a < e[0]:
		break
	else:
		a += -e[0]
		t += 1
		while f < len(rev) and rev[f][0] > a:
			heapq.heappush(l, (rev[f][1] - rev[f][0] + 1, rev[f][0], rev[f][1]))
			bal.append(rev[f][0])
			f += 1
		ans = len(bal) + 1 - t
		ma = min(ma, ans)
print(ma)


import sys
input = sys.stdin.readline
from heapq import heappop, heappush, heapify
n = int(input())
(b, _) = list(map(int, input().split()))
heap = []
heap2 = []
for _ in range(n - 1):
	(t, w) = list(map(int, input().split()))
	if t > b:
		heap.append(w + 1 - t)
	else:
		heap2.append((-t, -w))
heapify(heap)
heapify(heap2)
ans = len(heap) + 1
while heap:
	need = heap[0]
	if need > b:
		break
	b -= need
	heappop(heap)
	while heap2 and -heap2[0][0] > b:
		(t, w) = heappop(heap2)
		(t, w) = (-t, -w)
		heappush(heap, w + 1 - t)
	cur = len(heap) + 1
	ans = min(ans, cur)
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
limak = list(map(int, input().split()))
import heapq
pq = []
arr = []
for i in range(1, n):
	(ti, wi) = map(int, input().split())
	if ti > limak[0]:
		heapq.heappush(pq, wi - ti + 1)
	else:
		arr.append((ti, wi - ti + 1))
arr.sort(reverse=True)
rem = limak[0]
best = len(pq) + 1
cur = len(pq) + 1
idx = 0
while rem and pq:
	nxt = pq[0]
	heapq.heappop(pq)
	if rem < nxt:
		break
	rem -= nxt
	cur -= 1
	while idx < len(arr) and arr[idx][0] > rem:
		heapq.heappush(pq, arr[idx][1])
		idx += 1
		cur += 1
	best = min(best, cur)
print(best)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import math
import math
import heapq
import sys
from math import gcd
n = int(input())
(b, w) = map(int, input().split())
heap = []
heap1 = []
for _ in range(n - 1):
	(ba, w) = map(int, input().split())
	if ba > b:
		heap.append(w - ba + 1)
	else:
		heap1.append((-1 * ba, w))
heapq.heapify(heap)
heapq.heapify(heap1)
ans = len(heap) + 1
while heap:
	need = heap[0]
	if need > b:
		break
	b -= need
	heapq.heappop(heap)
	while heap1 and -1 * heap1[0][0] > b:
		(t, w) = heapq.heappop(heap1)
		t = -1 * t
		w = w
		heapq.heappush(heap, w + 1 - t)
	ans = min(ans, len(heap) + 1)
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
from fractions import Fraction
import heapq as hp
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
lis = []
(a, b) = (-1, -1)
for i in range(n):
	(ta, tb) = Ri()
	if i == 0:
		(a, b) = (ta, tb)
	else:
		lis.append([ta, tb, i])
lis.sort(key=lambda x: x[0])
cnt = 0
i = 0
for i in range(len(lis)):
	if lis[i][0] <= a:
		cnt += 1
	else:
		break
if lis[i][0] <= a:
	i += 1
curplace = n - (cnt + 1) + 1
place = curplace
h = []
hp.heapify(h)
for j in range(i, len(lis)):
	hp.heappush(h, lis[j][1] - lis[j][0] + 1)
i -= 1
while len(h) > 0:
	temp = hp.heappop(h)
	if temp <= a:
		a -= temp
		curplace -= 1
	else:
		break
	while i >= 0 and lis[i][0] > a:
		hp.heappush(h, lis[i][1] - lis[i][0] + 1)
		curplace += 1
		i -= 1
	place = min(place, curplace)
print(place)


import heapq
n = int(input())
num_balloons = int(input().split()[0])
better_teams = []
current_place = 1
worse_teams = []
for i in range(1, n):
	inp = input().split()
	team_balloons = int(inp[0])
	team_size = int(inp[1])
	if team_balloons > num_balloons:
		current_place += 1
		better_teams.append(team_size - team_balloons + 1)
	else:
		worse_teams.append([team_balloons, team_size])
heapq.heapify(better_teams)
best_place = current_place
worse_teams = sorted(worse_teams, key=lambda x: -x[0])
ind = 0
while True:
	if len(better_teams) == 0:
		break
	removed_team = heapq.heappop(better_teams)
	num_balloons -= removed_team
	current_place -= 1
	if num_balloons < 0:
		break
	while ind < len(worse_teams) and worse_teams[ind][0] > num_balloons:
		heapq.heappush(better_teams, worse_teams[ind][1] - worse_teams[ind][0] + 1)
		current_place += 1
		ind += 1
	if current_place < best_place:
		best_place = current_place
print(best_place)


import os
import io
import heapq
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = 0
out = []
n = int(input())
ii += 1
pq = []
diffs = []
arr = []
limak = int(input().split()[0])
ii += 1
for team in range(n - 1):
	(b, w) = map(int, input().split())
	ii += 1
	arr.append(b)
	diffs.append(w - b + 1)
arr1 = sorted(arr, reverse=True)
sortingbelike = zip(arr, diffs)
howtobeorz = sorted(sortingbelike)
diffs = [x for (_, x) in howtobeorz]
diffs1 = diffs[::-1]
place = 0
removed = 0
best = 300000
while True:
	while place < n - 1 and arr1[place] > limak:
		place += 1
		heapq.heappush(pq, diffs1[place - 1])
	best = min(best, place - removed + 1)
	if len(pq) == 0:
		break
	curr = heapq.heappop(pq)
	if curr > limak:
		break
	limak -= curr
	removed += 1
print(best)


import heapq
from bisect import bisect_right
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
res = []
(curr, we) = map(int, input().split())
for j in range(n - 1):
	(p, q) = map(int, input().split())
	res.append([p, q - p])
res.sort(reverse=True)
li = []
j = 0
ans = n
tot = 0
while j < n - 1:
	if res[j][0] > curr:
		heapq.heappush(li, res[j][1] + 1)
		j += 1
	else:
		ans = min(ans, j + 1 - tot)
		try:
			p = li[0]
		except:
			p = float('inf')
		if curr >= p:
			curr -= p
			heapq.heappop(li)
			tot += 1
		else:
			break
while curr >= 0:
	ans = min(ans, j + 1 - tot)
	try:
		p = li[0]
	except:
		p = float('inf')
	if curr >= p:
		curr -= p
		heapq.heappop(li)
		tot += 1
	else:
		break
print(ans)