#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main() {
  int k, n;
  cin >> n >> k;
  v1 p(n);
  for (int i = 0; i < (n); ++i) {
    cin >> p.at(i);
  }
  ll m = 1e18;
  for (int bit = 0; bit < (1 << n); ++bit) {
    int sum = 0;
    int ck = 0;
    for (int i = 0; i < (n); ++i) {
      if (bit & (1 << i)) {
        sum += p.at(i);
        ck++;
      }
    }
    if (ck != k || ck == 0) continue;
    if (m > sum) m = sum;
  }
  cout << m << endl;
}
