#include <bits/stdc++.h>
int main(void) {
  int max, fluet;
  int alt;
  int sum = 0;
  int price[999];
  if (scanf("%d%d", &max, &fluet) != 2) {
    return -1;
  }
  if (max > fluet) return -1;
  if (max > 1000) return -1;
  for (int i = 0; i < max; i++) {
    if (scanf("%d", &price[i]) != 1) {
      return -1;
    }
    if (price[i] < 1 || 1000 < price[i]) return -1;
  }
  for (int i = 0; i < max - 1; i++) {
    for (int j = i + 1; j < max; j++) {
      if (price[i] > price[j]) {
        alt = price[i];
        price[i] = price[j];
        price[j] = alt;
      }
    }
  }
  for (int k = 0; k < fluet; k++) {
    sum += price[k];
  }
  printf("%d\n", sum);
  return 0;
}
