#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int n; int p[100000], a[100000]; long long dp[100000][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; REP (i, n) cin >> p[i] >> a[i]; dp[n-1][0] = p[n-1]; dp[n-1][1] = a[n-1]; for (int i = n - 2; i >= 0; i--) { dp[i][0] = p[i] + max(dp[i+1][0], dp[i+1][1]); dp[i][1] = a[i] + max(p[i+1] + dp[i+1][0], a[i+1] + dp[i+1][1]); } cout << max(dp[0][0], dp[0][1]) << endl; return 0; }