n=int(input()) c=[] for i in range(n): a,b=map(int,input().split()) c+=[(a,-b)] X=10**20 g=X if n<=16: for i in range(1<>j)&1] g=min(g,abs(p)) else: pl=[-X,X] for i in range(1<<(n//2)): p=0 for j in range(n//2): p+=c[j][(i>>j)&1] pl+=[p] pl.sort() pr=[-X,X] for i in range(1<<(n-n//2)): p=0 for j in range(n-n//2): p+=c[n//2+j][(i>>j)&1] pr+=[p] pr.sort() from bisect import bisect_left for v in pl: y=bisect_left(pr,-v) g=min(g,abs(v+pr[y]),abs(v+pr[y-1])) print(g)