#include "bits/stdc++.h" using namespace std; //------------------------------- Libraries --------------------------------// //------------------------------- Type Names -------------------------------// using i64 = int_fast64_t; using seika = string; //akari : 1D, yukari : 2D, maki : 3D vector template using akari = vector; template using yukari = akari>; template using maki = akari>; //akane : ascending order, aoi : decending order template using akane = priority_queue, greater>; template using aoi = priority_queue; //------------------------------- Dubug Functions ---------------------------// inline void print() { cout << endl; } template void print(const First &first, const Rest &... rest) { cout << first << ' '; print(rest...); } //------------------------------- Solver ------------------------------------// void solve() { int n, m1 = 0, m2 = 0; cin >> n; akari as(n), bs(n); for (int i = 0; i < n - 1; i++) { cin >> as[i] >> bs[i]; m1 += as[i]; m2 += bs[i]; } int ans = 0; for (int x = 0; x <= m2; x++) { int y = m1 + x - m2, f = y >= 0; for (int j = 0; j < n - 1; j++) { f &= as[j] <= m2 + y - bs[j]; } ans += f; } cout << ans << endl; } int main() { solve(); return 0; }