n,k=map(int,input().split()) lst=sorted(map(int,input().split()),reverse=True) new_lst=[i for i in lst if i>=0] print(sum(new_lst[:k]))