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

  max_ = float('inf')
  for bit in range(1 << N):
    sum_ = 0
    if not(bin(bit).count('1') == K):
      continue
    for i in range(N):
      mask = 1 << i
      if bit & mask:
        sum_ += P[i]

    max_ = min(max_, sum_)

  print(max_)

if(__name__ == '__main__'):
  main()