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