#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::string;
using std::vector;
int main() {
  int K, N, c, sum, result = 1000000, count;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p.at(i);
  for (int i = 0; i < pow(2, N); i++) {
    c = i;
    sum = 0;
    count = 0;
    for (int j = 0; j < N; j++) {
      if (c % 2 == 1) {
        sum += p.at(j);
        count++;
      }
      c = int(c / 2);
    }
    if (result > sum && count >= K) result = sum;
  }
  cout << result;
}
