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