I=lambda:map(int,raw_input().split());n,m=I();w=I() def f(s): D={(s,s):0} for i in xrange(n-1): T={} for(t,h),v in D.items(): for a in[0,1]: if i-n+1m)*(m>0)else[0,sum(w)][m>0]