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