#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 1, k;
  cin >> n >> k;
  int *p = (int *)malloc(sizeof(n));
  if (!p) {
    cout << "malloc failed";
  }
  for (int i = 0; i < n; i++) cin >> p[i];
  int num;
  for (int i = 0; i < k; i++) {
    int min = INT_MAX;
    for (int j = i; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        num = j;
      }
    }
    p[num] = p[i];
    p[i] = min;
  }
  int sum = 0;
  for (int i = 0; i < k; i++) sum += p[i];
  cout << sum << endl;
  free(p);
  return 0;
}
