#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
vector<int> P;
int N, K;
ll dfs(set<int>& used, ll cur) {
  if (used.size() >= K) return cur;
  ll mi = INT64_MAX;
  for (int i = 0; i < ((int)(N)); i++) {
    if (used.count(i) > 0) continue;
    used.insert(i);
    mi = min(mi, dfs(used, cur + P[i]));
    used.erase(i);
  }
  return mi;
}
int main() {
  cin >> N >> K;
  P.resize(N);
  for (int i = 0; i < ((int)(N)); i++) {
    cin >> P.at(i);
  }
  set<int> used;
  cout << dfs(used, 0) << endl;
}
