#include <bits/stdc++.h>
using namespace std;
using ints_t = vector<int>;
using combi_t = vector<int>;
int get_sum(const ints_t &ints, const combi_t &combi) {
  int sum = 0;
  for (int i = 1; i <= combi.size(); ++i) {
    sum += ints[combi[i - 1] - 1];
  }
  return sum;
}
void gen_combis(const ints_t &ints, int k, combi_t &combi, int &min) {
  if (combi.size() == k) {
    int sum = get_sum(ints, combi);
    if (sum < min) {
      min = sum;
    }
    combi.pop_back();
  } else {
    for (int i = 1; i <= ints.size(); ++i) {
      if (find(combi.begin(), combi.end(), i) == combi.end()) {
        combi.push_back(i);
        gen_combis(ints, k, combi, min);
      }
    }
    if (!combi.empty()) {
      combi.pop_back();
    }
  }
}
void process(const ints_t &ints, int k) {
  combi_t combi;
  int min = INT_MAX;
  gen_combis(ints, k, combi, min);
  cout << min << "\n";
}
int main() {
  int n, k;
  cin >> n >> k;
  ints_t ints;
  while (n--) {
    int i;
    cin >> i;
    ints.push_back(i);
  }
  process(ints, k);
  return 0;
}
