import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

def main():
    n = II()
    aa, bb = [], []
    for _ in range(n):
        a, b = LI()
        aa.append(a)
        bb.append(b)

    dp = [inf]*n*(1 << n)
    for i in range(n): dp[(1 << i)*n+i] = 0

    ans = inf
    for s in range(1, 1 << n):
        for i in range(n):
            pre = dp[s*n+i]
            for j in range(n):
                if s >> j & 1: continue
                ns = s | 1 << j
                nv = bb[i]-aa[i]+aa[j]
                if pre > nv: nv = pre
                if ns+1 == 1 << n:
                    if nv < ans: ans = nv
                else:
                    if nv < dp[ns*n+j]: dp[ns*n+j] = nv

    print(ans)

main()