#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  vector<long long> p;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    p.push_back(a);
  }
  long long min = 1000 * 1000;
  vector<int> order;
  for (int i = 0; i < N; i++) {
    order.push_back(i);
  }
  do {
    long long sum = 0;
    for (int i = 0; i < K; i++) {
      sum += p.at(order.at(i));
    }
    if (sum < min) {
      min = sum;
    }
  } while (next_permutation(order.begin(), order.end()));
  cout << min << endl;
  return 0;
}
