import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) VT = [] for i in range(n): v, t = map(int, input().split()) VT.append((v,t)) VT.sort(key=lambda x: x[0]+x[1]) dp = set() dp.add(0) for v, t in VT: nx = set() for k in dp: nx.add(k) for k in dp: if k < t: nx.add(k+v) dp = nx dp = list(dp) print(max(dp))