#include using namespace std; #define rep(i, n) for(int i=0; i<(n); ++i) #define REP(i, d, n) for(int i=(d); i<(n); ++i) #define all(v) v.begin(), v.end() using ll = long long; using P = pair; int main() { int n; cin >> n; vector a(2*n); rep(i, 2*n){ cin >> a[i]; } vector diff(n); ll res = 0; rep(i, n){ diff[i] = a[2*i] - a[2*i+1]; res += diff[i]; } ll ans = LLONG_MIN; for(int i=n-1; i>=0; --i){ res -= 2 * diff[i]; ans = max(ans, res); } cout << ans << endl; return 0; }