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