n, k = input().strip().split()
n, k = [int(n), int(k)]

p = list(map(int, input().strip().split()))

def calc_min(cur_id, cur_v, cur_num_select):
    if cur_num_select == k:
        return cur_v
    elif cur_id == n and cur_num_select < k:
        return 1000 * 1000

    l_v = calc_min(cur_id + 1, cur_v + p[cur_id], cur_num_select + 1)
    r_v = calc_min(cur_id + 1, cur_v, cur_num_select + 0)

    return min([l_v, r_v])


print(calc_min(0, 0, 0))