n,k=gets.split.map &:to_i
w=$<.read.split.map &:to_i
min=10e9
[*1..n-1].combination(k-1).map{|i|i[0,0]=0;i<<n}.each{|i|
  max=0
  k.times{|j|
    max=[max, w[i[j], i[j+1]-i[j]].sum].max
  }
  min=[min,max].min
}
p min
