#include using namespace std; #define ll long long #define endl "\n" #define rep(i, a, n) for (int i = a; i < n; ++i) int main() { int n, k; cin >> n >> k; vector a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); reverse(a.begin(), a.end()); int ans = 0; rep(i, 0, k) { if (a[i] > 0) ans += a[i]; } cout << ans << endl; return 0; }