n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse = True) ans = 0 for i, num in enumerate(a): if i == k or num <= 0: break ans += num print(ans)