#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; if (n == 2) { return cout << 1 << '\n', 0; } int a = 0, b = 0; for (int _ = 0; _ < n - 1; ++_) { int x, y; cin >> x >> y; a += x; b += y; } int res = 0; for (int i = 0; i < 1e7; ++i) { int x = i, y = a + x - b; if (x > b or y > a) continue; if (x < 0 or y < 0) continue; ++res; } cout << res << '\n'; }