#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,K; cin >> N >> K; vector A, B; rep(i,N) { int a; cin >> a; if(a > 0) A.push_back(a); else B.push_back(a); } if(A.empty()) { sort(B.rbegin(), B.rend()); cout << B[0] << endl; return 0; } sort(A.rbegin(), A.rend()); int ans = 0; rep(i,min(K, int(A.size()))) ans += A[i]; cout << ans << endl; }