#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int *fruit = new int[n];
  for (int i = 0; i < n; i++) cin >> fruit[i];
  int fruit_min = 10000;
  for (int i = 0; i < 1 << n; i++) {
    int count = 0;
    int total = 0;
    for (int j = 0; j < n; j++) {
      if (i & 1 << j) {
        count++;
        total += fruit[j];
      }
    }
    if (count == m) {
      fruit_min = min(total, fruit_min);
    }
  }
  printf("%d\n", fruit_min);
  return 0;
}
