#include #define rep(i,n) for(int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() #define dunk(a) cout << (a) << endl using namespace std; typedef long long ll; signed int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n - 1); vector b(n - 1); rep(i, n - 1) cin >> a[i] >> b[i]; int res1 = accumulate(all(a), 0); int res2 = accumulate(all(b), 0); int ans = 0; rep(i, res2 + 1) { int c = (res1 + i) - res2; bool elf = (c >= 0) ? true : false; rep(j, n - 1) { if (a[j] > (c + res2) - b[j]) { elf = false; } } ans += elf; } dunk(ans); return 0; }