import sys
def order (p):
    return (sorted(p))         
def Mix_Juice (p):
    p[0] = len (p)
    p[1] = K
    a = order (p[2:p[0]])
    b = 0
    for i in range (0, K-1):
        b = b + a[i]
    return b
p = list(map(int, input().split()))
Mix_Juice (p)