_, k = [int(x) for x in input().split()] _n = sorted([int(x) for x in input().split()], reverse=True) n = [x for x in _n if x >= 0] n = n if len(n) != 0 else [max(_n)] print(sum(n[:k]))