N,K = map(int,input().split())
p = [int(m) for m in input().split()]
p.sort()
ans = 0

if K == 0:
    print(0)
elif K == 1:
    print(*p)
elif K == 2:
    print(p[0]+p[1])
else:
    for i in range(K):
        ans += p[i]
    print(ans)
