#include using namespace std; typedef long long ll; typedef pair P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;} template inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin>>n; vector> a(n); ll sum=0; rep(i, n){ ll p,q;cin>>p>>q; a[i] = make_pair(p,q); sum+=(p-q); } ll ans = sum; for(int i=n-1;i>=0;i--){ pair p = a[i]; sum = sum-(p.first-p.second)+(p.second-p.first); ans = max(ans, sum); } cout<