n, k = [int(x) for x in input().split()] a = sorted([int(x) for x in input().split()])[::-1] ans = 0 for i in range(k): if i == 0: ans += a[i] continue if a[i] < 0: break ans += a[i] print(ans)