#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N = int(readline()) m = map(int, read().split()) AB = list(zip(m, m)) # %% A, B = zip(*AB) # # %% INF = 10 ** 18 dp = [[INF] * N for _ in range(1 << N)] for n in range(N): dp[1 << n][n] = 0 for subset in range(1 << N): for newbook in range(N): if subset & (1 << newbook): continue newset = subset | (1 << newbook) for lastbook in range(N): x = max(dp[subset][lastbook], B[lastbook] - A[lastbook] + A[newbook]) if dp[newset][newbook] > x: dp[newset][newbook] = x # %% print(min(dp[-1]))