from bisect import bisect_left n = int(input()) lst = [] for _ in range(n): a, b = map(int, input().split()) lst.append((a, b)) L = lst[:n//2] R = lst[n//2:] def f(A): ret = {0} for a, b in A: nex = set() for s in ret: nex.add(s + a) nex.add(s - b) ret = nex return sorted(ret) L = f(L) R = [-1 << 60] + f(R) + [1 << 60] ans = 1 << 60 for l in L: l *= -1 p = bisect_left(R, l) ans = min(ans, l - R[p - 1], R[p] - l) print(ans)