# A N, K = list(map(int, input().split())) As = list(map(int, input().split())) positive_As = [a for a in As if a >= 0] sorted_As = sorted(positive_As) selected = sorted_As[-K:] print(sum(selected))