N = int(input()) src = [tuple(map(int,input().split())) for i in range(N)] MAX = 1000 mem = [(0,0)] for a,b in src: mem2 = [] for ma,mb in mem: mem2.append((ma+a,mb)) mem2.append((ma,mb+b)) if len(mem2) > MAX: mem = sorted(mem2, key=lambda x:max(x))[:MAX] else: mem = mem2 print(min([max(a,b) for a,b in mem]))