import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { solver(); } static void solver() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] diff1 = new long[(int) pow(2, n / 2)]; long[] diff2 = new long[(int) pow(2, n - n / 2)]; long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); b[i] = sc.nextLong(); } for (int i = 0; i < n / 2; i++) { int d = (int) pow(2, i); for (int j = 0; j < d; j++) { diff1[j + d] = diff1[j] - b[i]; diff1[j] = diff1[j] + a[i]; } } int res = n / 2; for (int i = 0; i < n - n / 2; i++) { int d = (int) pow(2, i); for (int j = 0; j < d; j++) { diff2[j + d] = diff2[j] - b[i + res]; diff2[j] = diff2[j] + a[i + res]; } } Arrays.sort(diff1); Arrays.sort(diff2); long min = Long.MAX_VALUE; int j = diff2.length - 1; for (int i = 0; i < diff1.length; i++) { min = Math.min(min, Math.abs(diff1[i] + diff2[j])); while (j != 0 && Math.abs(diff1[i] + diff2[j]) > Math.abs(diff1[i] + diff2[j - 1])) { j--; min = Math.min(Math.abs(diff1[i] + diff2[j]), min); } } System.out.println(min); } static long pow(long a, long n) { long A = a; long ans = 1; while (n >= 1) { if (n % 2 == 0) { A = A * A; n /= 2; } else if (n % 2 == 1) { ans = ans * A; n--; } } return ans; } static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }