#include using namespace std; int main() { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int sum = 0; for (int i = 0; i < k; i++) { if (a[i] <= 0) { if (i == 0) sum += a[i]; break; } sum += a[i]; } cout << sum << endl; return 0; }