#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  ;
  cin >> n;
  vector<uint64_t> v;
  cin >> k;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  uint64_t cnt = 0;
  for (int i = 0; i < k; ++i) {
    uint64_t min_pos = 0, min_val = 10000000001;
    for (int j = 0; j < n; ++j) {
      if (v[j] < min_val) {
        min_val = v[j];
        min_pos = j;
      }
    }
    cnt += min_val;
    v[min_pos] = 10000000001;
  }
  cout << cnt << endl;
}
