import java.util.Scanner; public class Main { Scanner in = new Scanner(System.in); public void solve() { int n = in.nextInt(); int[] a = new int[n], b = new int[n]; for(int i = 0; i < n; i++){ a[i] = in.nextInt(); b[i] = in.nextInt(); } int ap = 0, bp = 0; for(int i = 0; i < n; i++){ if(Math.abs(ap + a[i] - bp) < Math.abs(bp + b[i] - ap)){ ap += a[i]; }else{ bp += b[i]; } } System.out.println(Math.abs(ap - bp)); } public static void main(String[] args) { new Main().solve(); } }