#include <bits/stdc++.h>
int main() {
  int n, k, fruit[1000], i, sum = 0, max, price[1000], j;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i = i + 1) {
    scanf("%d", &fruit[i]);
  }
  max = fruit[1];
  for (j = 1; j <= k; j = j + 1) {
    for (i = 2; i <= n; i = i + 1) {
      if (max >= fruit[i]) {
        max = fruit[i];
      }
    }
    price[j] = max;
    max = fruit[j + 1];
  }
  for (j = 1; j <= k; j = j + 1) {
    sum = sum + price[j];
  }
  printf("%d\n", sum);
  return 0;
}
