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