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