#include <bits/stdc++.h>
using namespace std;

int main() {
  int N = 0, K = 0, P = 0, ans = 0;
  cin >> N >> K;
  cin >> P;
  sort(P,P + N - 1);
  for(int i = 0;i > K;i++){
    ans += P[i];
  }
  cout << ans << endl;
  return 0;
}
    