import java.io.*;
import java.util.*;
public class Main {
static class Cow{
int w, s;
public Cow(int w, int s){
this.w = w;
this.s = s;
}
}
static int N = 50010;
static Cow cows[] = new Cow[N];
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer stmInput = new StreamTokenizer(br);
stmInput.nextToken();
n = (int)stmInput.nval;
for(int i = 0; i < n; i++){
stmInput.nextToken();
int w = (int)stmInput.nval;
stmInput.nextToken();
int s = (int)stmInput.nval;
cows[i] = new Cow(w, s);
}
// 按w+s从小到大排序
Arrays.sort(cows, 0, n, (a, b) -> {return a.w + a.s - b.w - b.s;});
// 计算最大危险值
long res = (long)-2e9, sum = 0;
for(int i = 0; i < n; i++){
res = Math.max(res, sum - cows[i].s);
sum += cows[i].w;
}
System.out.println(res);
br.close();
}
}