def f l,m
$h[l+[m]]||=m<2?l.inject(:+):(1..l.size-m+1).map{|i|[l[0,i].inject(:+),f(l[i..-1],m-1)].max}.min
end
while(m,n=gets.split.map &:to_i)[0]>0
w=(1..n).map{gets.to_i}
$h={}
p m<n ?f(w,m):w.max
end