#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;
using P = pair<int, int>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  if (n == 1) {
    cout << p[0] << endl;
    return (0);
  }
  int ans = pow(10, 9);
  vector<int> v(n - 1);
  iota(v.begin(), v.end(), 1);
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[v[i - 1]];
  }
  if (sum < ans) ans = sum;
  while (next_permutation(v.begin(), v.end())) {
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += p[v[i - 1]];
    }
    if (sum < ans) {
      ans = sum;
    }
  }
  cout << ans << endl;
}
