#include <bits/stdc++.h>
int main(void) {
  int k, n;
  scanf("%d%d\n", &n, &k);
  if ((k < 1) || (1000 < k) || (n < 1) || (1000 < n) || (k > n)) {
    return -1;
  }
  int p[n], i = 0, j, temp;
  while (i < n) {
    scanf("%d", &p[i]);
    if ((p[i] < 1) || (1000 < p[i])) {
      return -1;
    }
    i++;
  }
  int sum = 0;
  i = 0;
  while (i < k) {
    j = i + 1;
    while (j < n) {
      if (p[j] < p[i]) {
        temp = p[i];
        p[i] = p[j];
        p[j] = p[i];
      }
      j++;
    }
    sum += p[i];
    i++;
  }
  printf("%d\n", sum);
  return 0;
}
