import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== public void solve() { int N = Integer.parseInt(sc.next()); int[] A = new int[N]; int[] B = new int[N]; int sumA = 0, sumB = 0; for (int i = 0; i < N -1 ; i++) { A[i] = Integer.parseInt(sc.next()); B[i] = Integer.parseInt(sc.next()); sumA += A[i]; sumB += B[i]; } int a1, b1, sa, ans = 0; boolean flg; if(sumA >= sumB) { sa = sumA - sumB; a1 = 0; for (; a1 <= sumB; a1++) { b1 = a1 + sa; flg = true; for (int j = 0; j < N - 1; j++) { if(A[j] > b1 + sumB - B[j] || B[j] > a1 + sumA - A[j]) { flg = false; break; } } if(flg) ans++; } } else { sa = sumB - sumA; b1 = 0; for (; b1 <= sumA; b1++) { a1 = b1 + sa; flg = true; for (int j = 0; j < N - 1; j++) { if(A[j] > b1 + sumB - B[j] || B[j] > a1 + sumA - A[j]) { flg = false; break; } } if(flg) ans++; } } out.println(ans); } // ================================================================== } class PP{ public int key, val; public PP(int key, int val) { this.key = key; this.val = val; } public int getKey() { return key; } public int getVal() { return val; } }