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

cheap = []

for m in range(k):
    for i in range(len(l)):
        flag = False
        for j in range(len(l)):
            if l[i] > l[j]:
                flag = True
                break
        if flag == False:
            cheap.append(l[i])
            l.remove(l[i])
            break

print(sum(cheap))