#include <bits/stdc++.h>
int main() {
  int N;
  int K;
  scanf("%d", &N);
  scanf("%d", &K);
  int p[N];
  int min[N];
  int sum = 0;
  int tmp;
  for (int i = 0; i < N; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (p[i] > p[j]) {
        tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
      }
    }
  }
  for (int i = 0; i < K; i++) {
    sum += p[i];
  }
  printf("%d", sum);
  return 0;
}
