#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ints;
  while (n--) {
    int i;
    cin >> i;
    ints.push_back(i);
  }
  sort(ints.begin(), ints.end());
  int min = INT_MAX;
  do {
    int sum = accumulate(ints.begin(), ints.begin() + k, 0);
    if (sum < min) {
      min = sum;
    }
  } while (next_permutation(ints.begin(), ints.end()));
  cout << min << "\n";
  return 0;
}
