#include <bits/stdc++.h>
int main(void) {
  int n, k, tmp, sum;
  int a[1000];
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    for (int j = 0; j < i; j++) {
      if (a[j] > a[i]) {
        tmp = a[i];
        for (int l = j; l < i; l++) {
          a[l + 1] = a[l];
        }
        a[j] = tmp;
      }
    }
  }
  for (int i = 0; i < k; i++) sum += a[i];
  printf("%d", sum);
  return 0;
}
