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