n,k = map(int,input().split()) ai = [int(i) for i in input().split()] ai.sort(reverse=True) print(ai) ans = 0 for i in range(k): if i == 0: ans += ai[i] elif ai[i] > 0: ans += ai[i] else: break print(ans)