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

i=0
while True:
    if len(p)==1:
        break
    if p[i]<=p[i+1]:
        i+=1
    else:
        a=p[i]
        p[i]=p[i+1]
        p[i+1]=a
        i=0
    if i==len(p)-1:
        break

ans=0
for i in range(k):
    ans+=p[i]
print(ans)
