#include <bits/stdc++.h>
int main() {
  int num, buy, i, j, c, total = 0;
  scanf("%d %d", &num, &buy);
  int p[buy];
  for (i = 0; i < num; i++) {
    scanf("%d", &p[i]);
  }
  for (i = 0; i < num; i++) {
    for (j = i + 1; j < num; j++) {
      if (p[i] > p[j]) {
        c = p[i];
        p[i] = p[j];
        p[j] = c;
      }
    }
  }
  for (i = 0; i < buy; i++) {
    total += p[i];
  }
  printf("%d\n", total);
}
