n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) ans=0 for i in range(1,k+1): ans=max(ans,sum(l[:i])) print(ans)