#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> p;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    p.push_back(a);
  }
  if (0) {
    for (int i = 0; i < N; i++) cout << p.at(i);
    cout << endl;
  }
  ll min = 1000 * 1000;
  for (ll bit = 0; bit < (1 << N); ++bit) {
    ll mask = 0;
    ll sum = 0;
    for (int i = 0; i < bit; ++i) {
      if (bit & (1 << i)) {
        mask |= (1 << i);
        sum += p.at(i);
      }
    }
    if (__builtin_popcount(mask) != K) {
      continue;
    }
    if (sum < min) {
      min = sum;
    }
  }
  cout << min << endl;
  return 0;
}
