import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] adds = new long[n]; long[] dp = new long[1 << n]; for (int i = 0; i < n; i++) { long a = sc.nextLong(); long b = sc.nextLong(); dp[0] += b; adds[i] = a + b; } long min = dp[0]; for (int i = 1; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if ((i & (1 << j)) != (1 << j)) { continue; } dp[i] = dp[i ^ (1 << j)] - adds[j]; break; } min = Math.min(min, Math.abs(dp[i])); } System.out.println(min); } }