// yukicoder No.1046 #include using namespace std; int main() { int n, k; cin >> n >> k; vector vec(n); for(int i = 0; i < n; ++i) cin >> vec[i]; sort(vec.rbegin(), vec.rend()); int sum = vec[0]; for(int i = 1; i < k; ++i) { if(vec[i] > 0) sum += vec[i]; else break; } cout << sum << "\n"; return 0; }