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