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