#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); // Ai <= sum(B) - Bi // A1 + sum(A) == B1 + sum(B) int N; cin >> N; N--; vector A(N), B(N); rep(i,N) cin >> A[i] >> B[i]; int sumA = accumulate(A.begin(), A.end(), 0); int sumB = accumulate(B.begin(), B.end(), 0); int ans = 0; for(int A1 = 0; A1 <= sumB; A1++) { int B1 = A1 + sumA - sumB; int ok = 1; rep(i,N) ok &= A[i] <= sumB + B1 - B[i]; ans += ok; } cout << ans << endl; }