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