import sys input = sys.stdin.readline N=int(input()) DP=[10**8]*100001 DP[0]=0 for i in range(N): a,b=map(int,input().split()) NDP=[10**8]*100001 for i in range(100001): NDP[i]=min(NDP[i],DP[i]+b) if i+a<100001: NDP[i+a]=min(NDP[i+a],DP[i]) DP=NDP ANS=100000000 for i in range(100001): ANS=min(ANS,max(i,DP[i])) print(ANS)