#include <bits/stdc++.h>
using namespace std;
struct Node {
int l, r;
bool operator< (const Node &t) const {
return l + r < t.l + t.r;
}
};
int n;
vector<Node> a;
int main(void) {
cin >> n;
for (int i = 0; i < n; ++i) {
int w, s;
cin >> w >> s;
a.push_back({w, s});
}
sort(a.begin(), a.end());
int res = -2e9;
int sum = 0;
for (auto [w, s] : a) {
res = max(sum - s, res);
sum += w;
}
cout << res;
return 0;
}