#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int main() {
  int N, K;
  cin >> N >> K;
  vi P(N);
  for (int i = (int)(0); i < (int)(N); ++i) cin >> P[i];
  int ans = 1000000000;
  for (int i = (int)(0); i < (int)(1 << N); ++i) {
    int c = 0;
    int s = 0;
    for (int j = (int)(0); j < (int)(N); ++j) {
      if (i >> j & 1) {
        c++;
        s += P[j];
      }
    }
    if (c == K) {
      ans = min(ans, s);
    }
  }
  cout << ans << endl;
}
