using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int N; private int[] A, B; private void Scan() { N = int.Parse(Console.ReadLine()); A = new int[N]; B = new int[N]; for (int i = 0; i < N; i++) { var line = Console.ReadLine().Split(' '); A[i] = int.Parse(line[0]); B[i] = int.Parse(line[1]); } } private long DFS(long aa,long bb,int n) { if(n == N) { return Math.Abs(aa - bb); } long a = DFS(aa + A[n], bb, n + 1); long b = DFS(aa, bb + B[n], n + 1); return Math.Min(a , b); } public void Solve() { Scan(); Console.WriteLine(DFS(0, 0, 0)); } }