#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c, temp, result = 1000000000;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < (int)(n); ++i) cin >> p[i];
  for (int i = 0; i < (int)(1 << n); ++i) {
    c = 0;
    for (int j = 0; j <= i; ++j)
      if (i & 1 << j) ++c;
    if (c != k) continue;
    temp = 0;
    for (int j = 0; j <= i; ++j)
      if (i & 1 << j) temp += p[j];
    result = min(result, temp);
  }
  cout << (result) << endl;
}
