#include using namespace std; #define rep(i,N) for(int (i)=0;(i) < (N); (i)++) #define all(V) V.begin(), V.end() using i64 = int_fast64_t; using P = pair; int main(){ int N; cin >> N; int in = 0, out = 0; int a,b; rep(i,N-1){ cin >> a >> b; in += a; out += b; } int ans = 0; for(int i = 0; i <= in; i++){ a = out + i - in; if(0 <= a && a <= out) ans++; } cout << ans << endl; }