#include <iostream>
#include <algorithm>
using namespace std;
const int N=50005;
struct Row{
int w,s;
bool operator<(const Row &b)const{
return (s+w)<(b.s+b.w);
}
}row[N];
int s[N],w[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++){
int s,w;
cin>>w>>s;
row[i]={w,s};
}
sort(row,row+n);
int sum=0;
int Max=-1e9;
for(int i=0;i<n;i++)
{
if(sum-row[i].s>Max) Max=sum-row[i].s;
sum+=row[i].w;
}
cout<<Max;
return 0;
}