N, K = [ int(a) for a in input().split(' ') ] alist = [ int(a) for a in input().split(' ') ] def is_valid(num_subl, inds): inds = sorted(inds) prev = -1 for i in range(num_subl): start = max(prev+1, K*(i+1)-1) end = min(start+(num_subl-i-1)*(K-1)+ (N-num_subl*K if i > 0 else 0), N-(num_subl-i-1)-1) if inds[i] not in range(start,end+1): return False prev = inds[i] return True agenda = [] enumed = list(enumerate(alist)) sortedl = sorted(enumed, key=lambda p:p[1]) for num_subl in range(1,N//K+1): if num_subl > 1: if min(agenda) < sum([ p[1] for p in sortedl[:num_subl] ]): break queue = [sortedl] while queue: queue.sort(key=lambda l: sum([ p[1] for p in l[:num_subl] ])) checking = queue.pop(0) if is_valid(num_subl, [ p[0] for p in checking[:num_subl] ]): agenda.append(sum([ p[1] for p in checking[:num_subl] ])) break if len(checking)>num_subl: for i in range(num_subl): queue.append(checking[:i]+checking[i+1:]) print(min(agenda))