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

  min_ = float('inf')

  all_ = list(range(N))
  for items in itertools.combinations(all_, K):
    sum_ = sum([P[i] for i in items])
    min_ = min(min_, sum_)

  print(min_)


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