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