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