#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  long unsigned int K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int total = 0;
  int mint = 10000000;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<1000> s(tmp);
    total = 0;
    if (s.count() == K) {
      for (int j = 0; j < N; j++) {
        if (s.test(j)) {
          total += p.at(j);
        }
      }
      mint = min(mint, total);
    }
  }
  cout << mint << endl;
  return 0;
}
