N = int(input()) hon = [] for _ in range(N): a,b = map(int,input().split()) hon.append((a,b)) inf = 10 ** 8 dp = [[inf] * N for _ in range(1 << N)] for i in range(N): dp[1 << i][i] = 0 for bit in range(1,1 << N): for i in range(N): if bit >> i & 1: for j in range(N): maskj = 1 << j if bit & maskj == 0: u = hon[i][1] - hon[i][0] + hon[j][0] dp[bit | maskj][j] = min(dp[bit | maskj][j],max(dp[bit][i],u)) ans = inf for i in range(N): if dp[-1][i] < ans: ans = dp[-1][i] print(ans)