program ss;
type
re=record
u,w:longint;
end;
var
i,j,k,m,n:longint;
b:array[0..10000]of longint;
a:array[1..10000]of re;
procedure init;
begin
assign(input,'rez.in');reset(input);
assign(output,'rez.out');rewrite(output);
read(n);
for i:=1 to n do
readln(a[i].u,a[i].w);
end;
procedure qsort(lx,rx:longint);
var
i,j,t1,t2:longint;
begin
i:=lx;j:=rx;t1:=a[i].u;t2:=a[i].w;
repeat
while (i<j) and(t1<a[j].u) do
j:=j-1;
if i<j then
begin
a[i].u:=a[j].u;
a[i].w:=a[j].w;
i:=i+1;
while (i<j) and(t1>a[i].u) do
i:=i+1;
if i<j then
begin
a[j].u:=a[i].u;
a[j].w:=a[i].w;
j:=j-1;
end;
end;
until i=j;
a[i].w:=t2;a[i].u:=t1;i:=i+1;j:=j-1;
if i<rx then qsort(i,rx);
if j>lx then qsort(lx,j);
end;
procedure make;
begin
for i:=1 to n do
b[i]:=a[i].w-a[i].u;
for i:=2 to n do
for j:=1 to i do
begin
if a[i].u>=a[j].w then
begin
k:=b[j]+a[i].w-a[i].u;
if k>b[i] then
b[i]:=k;
end;
end;
end;
begin
init;
qsort(1,n);
make;
j:=0;
for i:=1 to n do
if b[i]>j then
j:=b[i];
write(j);
close(input);
close(output);
end.