#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 2e5 + 10; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n, k; cin >> n >> k; vector v(n); for (auto& x : v) cin >> x; sort(v.rbegin(), v.rend()); if (v[0] <= 0) { printf("%d\n", v[0]); return 0; } int ans = 0; for (int i = 0; i < k; i++) { if (v[i] <= 0) break; ans += v[i]; } cout << ans << endl; return 0; }