#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (long long i = 0; i < p.size(); ++i) cin >> p[i];
  ;
  int min_num = (1e9);
  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
      if (bit & (1 << i)) {
        S.emplace_back(i);
      }
    }
    if (S.size() != K) continue;
    int sum_num = 0;
    for (int i = 0; i < (int)S.size(); ++i) {
      sum_num += p.at(S.at(i));
    }
    if (min_num > sum_num) min_num = sum_num;
  }
  cout << min_num;
  return 0;
}
