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