#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int const INF = 1001001001;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < (int)(n); i++) cin >> v[i];
  int ans = INF;
  for (int bit = 0; bit < (1 << n); ++bit) {
    vector<int> s;
    int sum = 0;
    for (int i = 0; i < (int)(n); i++) {
      if (bit & (1 << i)) {
        s.push_back(v[i]);
        sum += v[i];
      }
    }
    if (s.size() == k) {
      ans = min(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}
