n = int(input()) dp = {} dp[0] = 0 s = 0 for _ in range(n): a, b = map(int, input().split()) s += b ndp = {} for k, v in dp.items(): ndp[k] = max(ndp.get(k, 0), v) ndp[k + a] = max(ndp.get(k + a, 0), v + b) dp = ndp ans = 1 << 60 for k, v in dp.items(): ans = min(ans, max(k, s - v)) print(ans)