#include <bits/stdc++.h>
int main() {
  int N;
  int K;
  scanf("%d", &N);
  scanf("%d", &K);
  int p[N];
  int min[N];
  int sum = 0;
  int mins;
  for (int i = 0; i < N; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < K; i++) {
    min[i] = p[i];
  }
  for (int j = K; j < N; j++) {
    for (int k = 0; k < K; k++) {
      if ((p[j] > min[k]) && (p[j] <= min[k + 1])) {
        mins = min[k + 1];
        min[k + 1] = p[j];
        for (int x = k + 2; x < K; x++) {
          mins = min[x];
          min[x + 1] = mins;
        }
      }
    }
  }
  for (int i = 0; i < K; i++) {
    sum += min[i];
  }
  printf("%d", sum);
  return 0;
}
