N = int(input()) A, B = [None] * N, [None] * N for i in range(N): A[i], B[i] = map(int, input().split()) N2 = 1 << N inf = 10 ** 18 dp = [[inf] * N for i in range(N2)] for i in range(N): dp[1 << i][i] = 0 for s in range(1, N2): for i in range(N): for j in range(N): if (s >> j) & 1 or (s >> i) & 1 == 0: continue ns = s | (1 << j) dp[ns][j] = min(dp[ns][j], max(dp[s][i], B[i] - A[i] + A[j])) print(min(dp[-1]))