n=int(input()) dp=[1<<30]*(1000*n+1);dp[0]=0 for i in range(n): a,b=map(int,input().split()) dp2=[1<<30]*len(dp) for j in range(len(dp2)): if j+a