N,K = map(int,input().split()) A = list(map(int,input().split())) A = sorted(A)[::-1] result = 0 for i in range(K): if A[i]>0: result += A[i] else: print(result) exit() print(result)