#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int* vals = new int[n];
  int* comb = new int[k];
  int tmp_val;
  int min = 1000 * 1000;
  int pattern = pow(n, k);
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
  }
  for (int i = 0; i < pattern; i++) {
    int tmp = i;
    tmp_val = 0;
    for (int j = 0; j < k; j++) {
      comb[j] = tmp % n;
      tmp_val += vals[comb[j]];
      tmp /= n;
    }
    bool flag = false;
    for (int j1 = 0; j1 < k; j1++) {
      for (int j2 = 0; j2 < k; j2++) {
        if (j1 == j2) continue;
        if (comb[j1] == comb[j2]) {
          flag = true;
          break;
        }
      }
      if (flag) break;
    }
    if (flag) continue;
    if (min > tmp_val) {
      min = tmp_val;
    }
  }
  cout << min << endl;
  return 0;
}
