#include "bits/stdc++.h" using namespace std; // コンテスト中のみ //#define int long long #define ll long long #define rep(i,n) for(int i = 0; i < (n); i++) #define P pair #define ld long double ll INF = (1LL << 60); int MOD = 1000000007; ll N; ll p[100010], a[100010]; ll dp[100010][2]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; rep(i, N)cin >> p[i] >> a[i]; dp[0][0] = p[0], dp[0][1] = a[0]; for (int i = 1; i < N; i++) { dp[i][0] = max(dp[i - 1][0] + p[i], dp[i - 1][1] + p[i] * 2); dp[i][1] = max(dp[i - 1][0] + a[i], dp[i - 1][1] + a[i] * 2); } ll ans = 0; rep(i, 2)ans = max(ans, dp[N - 1][i]); cout << ans << endl; return 0; }