#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.rbegin(), a.rend()); int ans = 0; for (int i = 0; i < k; ++i) { if (i == 0) { ans += a[i]; } else { if (0 <= a[i]) { ans += a[i]; } } } cout << ans << endl; return 0; }