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