#include #define rep(i,n) for(int i = 0; i < n; i++) #define REP(i,s,n) for(int i = s; i < n; i++) typedef long long ll; using namespace std; using Graph = vector>; ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); } ll ceil(const ll a, const ll b) { return (a + b - 1) / b; } int main(){ int n,k; cin >> n >> k; vectorv(n); rep(i,n)cin >> v[i]; int ans = 0; sort(v.rbegin(),v.rend()); rep(i,k)if(v[i] >= 0)ans += v[i]; cout << ans << endl; return 0; }