#include using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; ++i) cin >> a[i]; sort(a.rbegin(), a.rend()); int ans = 0; for (int i = 0; i < k; ++i) { if (a[i] < 0) break; ans += a[i]; } cout << ans << '\n'; return 0; }