#include using namespace std; using ll=long long; #define rep2(i, a, n) for(int i = (a); i < (n); i++) #define rep(i, n) rep2(i,0,n) int main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); int n,k,x;cin>>n>>k; vector hoge; rep(i,n){ cin>>x; hoge.push_back(x); } sort(hoge.rbegin(),hoge.rend()); int ans=hoge[0]; rep2(i,1,k-1){ if(hoge[i]>0)ans+=hoge[i]; else break; } cout<