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