n,k = map(int,input().split()) A = sorted(map(int,input().split()))[::-1] ans = 0 for i in range(k): if i == 0: ans += A[i] continue if A[i] > 0: ans += A[i] print(ans)