#include <bits/stdc++.h>
using namespace std;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
long long mod = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < (int)(n); i++) cin >> p[i];
  long long ans = 9000000;
  for (int s = 0; s < (1 << n); s++) {
    long long total = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s >> i & 1) {
        total += p[i];
        cnt++;
      }
    }
    if (cnt == k) ans = min(ans, total);
  }
  cout << ans;
  return 0;
}
