n,k = map(int, input().split())
p = list(map(int, input().split()))

bag = []
bag_max = 0

for i in range(n):

    if i < k:
        bag.append(p[i])
        if bag_max < p[i]:
            bag_max = p[i]
    else:
        if bag_max > p[i]:
            bag.append(p[i])
            bag.remove(bag_max)
            bag_max = p[i]

print(sum(bag))