n,k=map(int,input().split()) a=sorted(list(map(int,input().split())),reverse=True) ans=a[0] if ans<=0: print(ans) else: for i in range(k): if a[i]>0: ans+=a[i] else: break print(ans)