#include <bits/stdc++.h>
int main() {
  int n, i, j, p[1000], k, min = 1000, m, a;
  char s[1000000];
  scanf("%d %d\n", &n, &k);
  fgets(s, sizeof(s), stdin);
  p[0] = atoi(strtok(s, " "));
  for (i = 1; i < n; i++) {
    p[i] = atoi(strtok(NULL, " "));
  }
  for (i = 0; i < k; i++) {
    for (j = 0; j < n - i; j++) {
      if (min >= p[j]) {
        min = p[j];
        m = j;
      }
    }
    a += min;
    p[m] = 1000;
    min = 1000;
  }
  printf("%d\n", a);
  return 0;
}
