N=int(input()) A_B=[input().split(" ") for i in range(N)] #A[i]:i+1の問題をAが解く時間 A=[int(x[0]) for x in A_B] #B[i]:i+1の問題をBが解く時間 B=[int(x[1]) for x in A_B] #貪欲法 greed_A=0 greed_B=0 for i in range(N): if greed_A + A[i] < greed_B+B[i]: greed_A+=A[i] else: greed_B+=B[i] upper_A=max(greed_A,greed_B) #upper_A=sum(A) dp=[0] * (upper_A + 1) for i in range(N): #参照回数を削る a=A[i] b=B[i] for j in range(upper_A,a-1,-1): dp[j]=max(dp[j],dp[j - a] + b) sum_B=sum(B) print(min([max(a,sum_B - dp[a]) for a in range(upper_A+1)]))