#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> box;
  for (int i = 0; i < n; ++i) {
    cin >> box[i];
  }
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    int min = 0;
    int index;
    for (int j = 0; j < n - i; ++j) {
      if (min > box[j]) {
        min = box[j];
        index = j;
      }
    }
    box.erase(box.begin() + index);
    sum += min;
  }
  cout << sum << endl;
  return 0;
}
