n,k = map(int,input().split()) a = list(map(int,input().split())) a = sorted(a)[::-1] res = 0 for i in range(k + 1): res = max(res, sum(a[:i])) print(res)