n, k = map(int, input().split())
a_lst = list(map(int, input().split()))
a_lst.sort()
if n > k or k == 3:
    print(a_lst[0]+a_lst[1]+a_lst[2])
elif k == 2:
    print(a_lst[0]+a_lst[1])
else:
    print(a_lst[0])