program shizi;
type
fxz=array[1..100]of longint;
var
f1,f2:text;
i,j,k,min,step,n,l:longint;
a:fxz;
begin
assign(f1,'shizi.in');
assign(f2,'shizi.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i]);
l:=n;step:=0;
for i:=1 to l-1 do
begin
min:=a[1]+a[n];k:=n;
for j:=1 to n-1 do
if a[j]+a[j+1]<=min then begin min:=a[j]+a[j+1];k:=j;end;
step:=step+min;
if k=n then begin a[1]:=min;n:=n-1;end
else begin a[k]:=min;
if k<>n-1 then for j:=k+1 to n-1 do a[j]:=a[j+1];
n:=n-1;
end;
end;
writeln(f2,step);
close(f1);close(f2);
end.