{整理书本}
{水题}
{yangbohua}
{time: 2010-10-25}
program book;
var
f:array[0..400,0..400] of longint;
w:array[0..400] of longint;
n,r1,r2,i,j,k,min:longint;
begin
assign(input,'book.in');
reset(input);
assign(output,'book.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(r1,r2);
w[i]:=w[i-1]+r1-r2;
end;
for i:=n-1 downto 1 do
for j:=i+1 to n do
begin
min:=maxlongint;
for k:=i to j-1 do
if f[i,k]+f[k+1,j]<min
then min:=f[i,k]+f[k+1,j];
f[i,j]:=min+w[j]-w[i-1];
end;
writeln(f[1,n]);
close(input);
close(output)
end.