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) m = -1 for k in dp: if k < t: if k+v >= t: nx.add(k+v) else: m = max(m, k+v) if m != -1: nx.add(m) dp = nx dp = list(dp) print(max(dp))