f=lambda:map(int,input().split()) n,k=f() *a,=f() a=sorted(a)[::-1] ans=a[0] for i in a[1:k]: ans+=max(i,0) print(ans)