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