N = int(input()) A, B = [0]*N, [0]*N for i in range(N): A[i], B[i] = map(int, input().split()) INF = 10**18 dp = [[INF]*N for _ in range(1 << N)] for i in range(N): dp[1 << i][i] = 0 for i in range(1 << N): for a in range(N): for b in range(N): # a が最後で b を追加する if not (i >> a) & 1: continue if (i >> b) & 1: continue cost = max(dp[i][a], (B[a] - A[a]) + A[b]) dp[i | (1 << b)][b] = min(dp[i | (1 << b)][b], cost) print(min(dp[-1]))