N = int(input()) A_li = [0] B_li = [0] aa = bb = bsum = 0 for i in range(N): a,b = map(int,input().split()) A_li.append(a) B_li.append(b) if aa < bb: aa += a else: bb += b bsum += b ma = max(aa,bb) + 1 dp = [0] * ma for i in range(1,N+1): weight = A_li[i] value = B_li[i] for w in range(ma-1 , weight-1 , -1): if dp[w] < dp[w-weight] + value: dp[w] = dp[w-weight] + value ans = 10**20 for w in range(1,ma): ans1 = max(w, (bsum - dp[w])) ans = min(ans,ans1) print(ans)