import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt
  val p = Array.fill(N)(sc.nextInt)

  val z = p.combinations(K).map(_.sum).min
  println(z)
}
