fruit_count, buy_count = gets.chomp.split(' ').map{|i| i.to_i}

fruit_prices = gets.chomp.split(' ').map{|i| i.to_i}

combination_fruit_prices = fruit_prices.combination(buy_count).to_a.map{|arr| arr.sum}.sort

puts combination_fruit_prices.first
