from sys import stdin def main(): #入力 readline=stdin.readline N,K=map(int,readline().split()) A=list(map(int,readline().split())) A.sort(reverse=True) c=0 res=0 for i in range(N): if A[i]>0: c+=1 res+=A[i] if c==K: break if c==0: res+=A[0] print(res) if __name__=="__main__": main()