#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, s = 0, m = 100000000;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < (int)(N); i++) {
    cin >> v[i];
  }
  for (int bit = 0; bit < (1 << N); ++bit) {
    bitset<1000> a(bit);
    s = 0;
    if ((int)a.count() == K) {
      for (int j = 0; j < (int)(N); j++) {
        if (a.test(j)) s += v[j];
      }
      if (s < m) m = s;
    }
  }
  cout << m << endl;
}
