{*******************************************}
{* Program name: busses *}
{* Input file: busses.in *}
{* Ouptut file: busses.out *}
{* Date: 2008.10.29 *}
{* Programmer: Peng Bo *}
{*******************************************}
program busses;
type
sz=array[1..10]of byte;
var
s:sz;
n,g:qword;
i:byte;
f:text;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main(h,x:qword);
var
i:byte;
{--------------------------}
function min:qword;
begin
if x<10
then
min:=x
else
min:=10;
end;{min}
{--------------------------}
begin
if x>0
then
for i:=1 to min do
main(h+s[i],x-i)
else
if h<g
then
g:=h;
end;{main}
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
assign(f,'busses.in');
reset(f);
for i:=1 to 10 do
read(f,s[i]);
read(f,n);
close(f);
{===========}
g:=18446744073709551615;
main(0,n);
{===========}
assign(f,'busses.out');
rewrite(f);
write(f,g);
close(f);
end.