n, k = map(int, input().split()) a = list(map(int, input().split())) a = [e for e in a if e > 0] a.sort(reverse=True) ans = sum(a[:k]) print(ans)