#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<Pi> vec;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    vec.emplace_back(a, b);
  }
  sort(all(vec));
  vint sum(N+1, 0);
  rep(i, N) sum[i+1] = sum[i]+vec[i].second;
  rep(i, N) sum[i+1] -= vec[i].first;
  vint sum2(N+1, 0);
  rep(i, N) sum2[i+1] = sum[i+1]-vec[i].second;
  int ans = 0, mn = inf;
  rep(i, N) {
    chmin(mn, sum2[i+1]);
    chmax(ans, sum[i+1]-mn);
  }
  cout << ans << endl;

  return 0;
}

