import sys
#果物の種類Nと，購入数K
N, K = map(int, input().split())

#果物値段A
A = list(map(int, input().split()))
A = sorted(A, reverse = False)
#print(N, K)
#print(A)
ans=0
#C = 0

for i in A:
    ans += A.pop(0)
    #print(ans)
    #print(ans)
    """
    if C == K-1:
        print(ans)
        sys.exit()
"""
print(ans)


