#include <bits/stdc++.h>
int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int n, i, j;
  int count = 0;
  int k;
  int sum = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  int buf[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &buf[i]);
  }
  if (n < 0 || k < 0) return 0;
  if (n < k) {
    printf("%d", buf[0]);
    return 0;
  }
  if (k == 1) {
    printf("%d", buf[0]);
    return 0;
  }
  qsort(buf, n, sizeof(int), cmpfunc);
  for (j = 0; j < n - 1; j++) {
    if (count == k) break;
    sum += buf[j];
    count += 1;
  }
  printf("%d", sum);
  return 0;
}
