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

P = list(map(int,input().split()))

ans = 0

for i in range(k):

    m = min(P)

    ans += m

    P.remove(m)

print(ans)
import heapq

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

P = list(map(int,input().split()))

ans = 0

heapq.heapify(P)

for i in range(k):

    ans += heapq.heappop(P)

print(ans)
n, k = list(map(int, input().split()))
P = list(map(int, input().split()))
ans = 0
for i in range(k):
    m = min(P)
    ans += m
    P.remove(m)
print(ans)

import heapq

n, k = list(map(int, input().split()))
P = list(map(int, input().split()))
ans = 0
heapq.heapify(P)
for i in range(k):
    ans += heapq.heappop(P)
print(ans)

+import heapq + +heapq.heapify(P) -    m = min(P) -    ans += m -    P.remove(m) +    ans += heapq.heappop(P)