#include <bits/stdc++.h>
void swap(int x, int y) {
  int temp;
  temp = x;
  x = y;
  y = temp;
}
int main(void) {
  int N, K, i, a, b, x, y;
  scanf("%d", &N);
  scanf("%d", &K);
  int h[N];
  for (i = 0; i <= N; i++) {
    int p;
    scanf("%d", &p);
    h[i] = p;
  }
  for (a = 0; a < N - 1; a++) {
    for (b = N - 1; b >= a + 1; b--) {
      if (h[b] < h[b - 1]) {
        x = h[b];
        y = h[b - 1];
        swap(x, y);
      }
    }
  }
  i = 0;
  int sum = 0;
  for (i = 0; i < K; i++) {
    sum = sum + h[i];
  }
  printf("\n%d\n", sum);
  return 0;
}
