n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() import bisect b=bisect.bisect_right(a,0) ans=min(k,n-b) print(max(a[-1],sum(a[-ans:])))