#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int ans = INT_MAX;

void cout1 (int level, int max_level, vector <int> &p, vector <int> &q, int k) {
  int size = q.size();
  if (level == max_level) {
    q[level] = 0;
    // printVec(q);
    int count = 0;
    int ans2 = 0;
    for (int i = 0; i < size; i++) {
      count = count + q[i];
      if (q[i] == 1) {
        ans2 = ans2 + p[i];
      }
    }
    // cout << "count = " << count << endl;
    // cout << "ans2 = " << ans2 << endl;
    if (count == k) {
      if (ans > ans2) {
        ans = ans2;
      }
    }
    // cout <<"------" << endl;
    q[level] = 1;
    for (int i = 0; i < size; i++) {
      count = count + q[i];
      if (q[i] == 1) {
        ans2 = ans2 + p[i];
      }
    }
    if (count == k) {
      if (ans > ans2) {
        ans = ans2;
      }
    }
    return 0;
  }
  q[level] = 0;
  cout1(level + 1, max_level, p, q, k);
  
  q[level] = 1;
  cout1(level + 1, max_level, p, q, k);

}
int main() {

  int n, k;
  cin >> n >> k;
  vector <int> p(n);
  vector <int> q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  cout1 (0, n, p, q, k);
  cout << ans << endl;
	return 0;
}
