def insertion_sort(a):
    for j in range(1, len(a)):
        key = a[j]
        # a[j]をソート列a[0..j-1]に挿入
        i = j-1
        while (i>-1) and (a[i]>key):
            a[i+1] = a[i]
            i = i-1
        a[i+1] = key


N=int(input())
K=int(input())
a=[]
Sum=0

while N>0:
    auau=int(input())
    a.append(auau)
    N-=1
insertion_sort(a)
while K>0:
    Sum+=a[K-1]
    K-=1
print(Sum)