#include <bits/stdc++.h>
using namespace std;
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 count;
  if (level == max_level + 1) {
    int ans2 = 0;
    for (int i = 0; i < max_level; i++) {
      count = count + q[i];
      if (q[i] == 1) {
        ans2 = ans2 + p[i];
      }
    }
    if (count == k) {
      if (ans > ans2) {
        ans = ans2;
      }
    }
    return;
  }
  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;
}
