N,K = map(int,input().split())
p = list(map(int,input().split()))
result = []
#初期リスト
for i in range(K):
    result.append(p[i])

for i in range(N-K,K):
    for j in range(K):
        if p[i] < result[j]:
            result[j] = p[i]
            break
print(sum(result))