N,K = map(int, input().split()) F = list(map(int, input().split())) F.sort(reverse=True) A = F[0] for i in range(1, N + 1): if i < K and F[i] > 0: A += F[i] else: break print(A)