#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; V<> a(n), b(n); for (int i = 1; i < n; ++i) { cin >> a[i] >> b[i]; } int sa = accumulate(begin(a), end(a), 0); int sb = accumulate(begin(b), end(b), 0); int res = 0; for (a[0] = 0; a[0] <= sb; ++a[0]) { b[0] = a[0] + sa - sb; if (b[0] < 0 or b[0] > sa) continue; int ta = accumulate(begin(a), end(a), 0); int tb = accumulate(begin(b), end(b), 0); bool ok = true; for (int i = 0; i < n; ++i) { if (a[i] > tb - b[i]) { ok = false; break; } if (b[i] > ta - a[i]) { ok = false; break; } } res += ok; } cout << res << '\n'; }