from operator import itemgetter from itertools import * from bisect import * from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] # n<=32だから半分全列挙 def main(): inf=1<<63 n=II() ab=LLI(n) # AがBより何点多いかを前後半に分けて全列挙する def alldiff(si,ei): s=set() s.add(0) for a,b in ab[si:ei]: ns=set() for d in s: ns.add(d+a) ns.add(d-b) s=ns return list(sorted(s)) pre=alldiff(0,n//2) pos=alldiff(n//2,n) #print(pre) #print(pos) # しゃくとり法で絶対値の最小値を探す # 前半(pre)の値一つに対して、後半(pos)の値2つと比較の必要がある # 前半の値がa=3で、pos=[-5,1,6]だったら、 # -5(3と足して負になる),1(3と足して正になる)と比較する ans=inf j=len(pos)-1 for i,a in enumerate(pre): while j>0 and a+pos[j]>=0:j-=1 ans=min(ans,abs(a+pos[j]),abs(a+pos[j+1])) print(ans) main()