#include using namespace std; int main() { int n; cin >> n; vector s(n + 1); for (int i = 0; i < n; i++) { int64_t x, y; cin >> x >> y; s.at(i + 1) = s.at(i) + x - y; } cout << 2 * *max_element(s.begin(), s.end()) - s.at(0) - s.at(n) << endl; }