#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  char n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < (k); ++i) {
    ans += a[i];
  }
  cout << ans << endl;
}
