n,k = map(int, input().split()) l = sorted(list(map(int, input().split()))) a = l[-1] if a >= 0: l = [max(x,0) for x in l] a = sum(l[-k:]) print(a)