#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  cin >> N >> K;
  int p[N + 10];
  for (int i = 0; i < N; i++) cin >> p[i];
  vector<int> vec(N, 1);
  for (int i = 0; i < K; i++) vec[i] = 0;
  int total_min = N * 10000;
  do {
    int total = 0;
    for (int i = 0; i < N; i++) {
      if (vec[i] == 0) total += p[i];
    }
    if (total < total_min) total_min = total;
  } while (prev_permutation(vec.begin(), vec.end()));
  cout << total_min << endl;
}
