#include <bits/stdc++.h>
using namespace std;
void solve()
{
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
int ans = 0;
for (int i = 0; i < m; i++)
{
if (a[i] < 0)
ans += a[i];
}
cout << abs(ans);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHNvbHZlKCkKewp9CgppbnQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKCiAgICBpbnQgbiwgbTsKICAgIGNpbiA+PiBuID4+IG07CgogICAgdmVjdG9yPGludD4gYShuKTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KCiAgICBzb3J0KGEuYmVnaW4oKSwgYS5lbmQoKSk7CgogICAgaW50IGFucyA9IDA7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspCiAgICB7CiAgICAgICAgaWYgKGFbaV0gPCAwKQogICAgICAgICAgICBhbnMgKz0gYVtpXTsKICAgIH0KCiAgICBjb3V0IDw8IGFicyhhbnMpOwp9