#include <bits/stdc++.h>
int main() {
  int i = 0;
  int n, k;
  scanf("%d %d", &n, &k);
  int s;
  int array[n];
  int z;
  for (z = 0; z < 1000; z++) {
    array[i] = 0;
  }
  while (scanf("%d", &s) == 1) {
    array[i] = s;
    i++;
    if (i == n - 1) {
      break;
    }
  }
  int a, b, tmp;
  for (a = 0; a < n; a++) {
    for (b = a + 1; b < n; b++) {
      if (array[a] > array[b]) {
        tmp = array[a];
        array[a] = array[b];
        array[b] = tmp;
      }
    }
  }
  int sum = 0, c;
  for (c = 0; c < k; c++) {
    sum = sum + array[c];
  }
  printf("%d\n", sum);
  return 0;
}
