def main():
    N , K = map(int, input().split())

    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    import itertools
    p = itertools.permutations(A_list, K)
    ans = 100000000000
    for val in p :
        ans_new = sum(val)
        if ans_new < ans :
            ans = ans_new
        #print(val)

    print(ans)

if __name__ == '__main__':
    main()
