N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) ans = A[0] for i in range(1, K): ans += max(0, A[i]) print(ans)