# coding: utf-8 N,K=map(int,input().split()) A=list(map(int,input().split())) A.sort() for i in range(N): if A[i]<0: A[i]=0 print(sum(A[N-K:]))