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