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