#include <bits/stdc++.h>
int compareInt(const void* a, const void* b) {
  int aNum = *(int*)a;
  int bNum = *(int*)b;
  return aNum - bNum;
}
int main() {
  int n = 0;
  int k = 0;
  int p[1001] = {};
  int sum = 0;
  scanf("%d %d", &n, &k);
  int i, j;
  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  qsort(p, sizeof(p) / sizeof(p[0]), sizeof(int), compareInt);
  while (p[i] == 0) {
    i++;
  }
  for (j = i; j < i + k; j++) {
    sum += p[j];
  }
  printf("%d", sum);
  return 0;
}
