#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; } V<> x(n - 1), y (n - 1); int a = 0, b = 0; for (int i = 0; i < n - 1; ++i) { cin >> x[i] >> y[i]; a += x[i]; b += y[i]; } int p = 0, q = 0; for (int i = 0; i < n - 1; ++i) { int t = x[i]; for (int j = 0; j < n - 1; ++j) if (j != i) { t -= y[j]; } p += max(t, 0); t = y[i]; for (int j = 0; j < n - 1; ++j) if (j != i) { t -= x[j]; } q += max(t, 0); } int res = 0; for (int i = -1e8; i < 1e8; ++i) { int x = i, y = a + x - b; if (x > b or y > a) continue; if (x < p or y < q) continue; ++res; } cout << res << '\n'; }