#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); 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 ans = 0; for (int i = 0; i < K; ++i) { if (a[i] <= 0 && i > 0) break; ans += a[i]; } cout << ans << newl; return 0; }