#include using namespace std; using ll = long long; constexpr long long MOD = 1000000007; int main(){ ll n,k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater()); ll ans = 0; for (ll i = 0; i < k; i++) { if (a[i] < 0) break; ans += a[i]; } cout << ans << endl; }