program EmberAsh;
var
a,b:array[0..10] of longint;
i,j,k,m,n,ss,max:longint;
BEGIN
assign(input,'busses.in');reset(input);
assign(output,'busses.out');rewrite(output);
for i:=1 to 10 do
read(a[i]);
readln(n);
b[0]:=0;
for i:=1 to 9 do
b[i]:=200+1;
for i:=0 to n-1 do
begin
max:=b[i mod 10];
for j:=1 to 9 do
begin
ss:=(i+j) mod 10;
if max+a[j]<b[ss] then
b[ss]:=max+a[j];
end;
b[i mod 10]:=max+a[10];
end;
m:=n mod 10;
writeln(b[m]);
close(input);close(output);
END.