import sys input = sys.stdin.readline def main(): n = int(input()) A = [list(map(int, input().split())) for _ in range(n)] INF = 10**18 DP = [[INF for _ in range(n)] for _ in range(1 << n)] for i in range(n): DP[1 << i][i] = 0 for bit in range(1, 1 << n): seen = set() for i in range(n): if (bit >> i) & 1: seen.add(i) for i in range(n): if i in seen: for j in range(n): if j not in seen: nbit = bit | (1 << j) DP[nbit][j] = min(DP[nbit][j], max(DP[bit][i], A[i][1] - A[i][0] + A[j][0])) print(min(DP[-1])) if __name__ == '__main__': main()