#include using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; i++)cin >> a[i]; sort(a.begin(), a.end(), greater()); int sum = a.front(); for(int i = 1; i < k && a[i] >= 0; i++) { sum += a[i]; } cout << sum << endl; }