N,K = map(int,input().split()) List = list(map(int,input().split())) List = sorted(List) ans = 0 for i in range(K): if List[-(i+1)] <= 0: break else: ans += List[-(i+1)] print(ans)