#include #include #include #include using namespace std; typedef pair Paint; bool pairSum(const Paint& pf,Paint&ps){//sortCompare return pf.first+pf.second > ps.first+ps.second; } int main(){ int n;cin>>n; if(n==2){ cout << 1 << endl; return 0; } vector a(n-1); int a_sm = 0; int b_sm = 0; for(int i = 0; n-1 > i; i++){ cin>>a[i].first>>a[i].second; a_sm += a[i].first; b_sm += a[i].second; } sort(a.begin(),a.end(),pairSum); for(int i = 1; n-1 > i; i++){ a[0].first -= a[i].second; a[0].second -= a[i].first; } if(a[0].first <= 0 || a[0].second <= 0){ cout << min(a_sm,b_sm)+1 << endl; }else{ cout << a_sm - a[0].first + 1 << endl; } }