#pragma GCC optimize("Ofast") #include using namespace std; #define REP(i,n) for(int i = 0; i < (int)(n); ++i) #define ALL(a) (a).begin(),(a).end() typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; vector A(N+1,0), B(N+1,0); cin >> N; REP(i,N-1){ cin >> A[i] >> B[i]; } int s = accumulate(ALL(A), 0); int t = accumulate(ALL(B), 0); int ma = 0, mb = 0; REP(i,N-1){ ma = max(ma, A[i]+B[i]-s); mb = max(mb, A[i]+B[i]-t); } cout << min(t-ma,s-mb) + 1 << endl; return 0; }