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