n, k = map(int, input().strip().split()) c = list(map(int, input().strip().split())) print(min([sum(c[i::(k*2+1)]) for i in range(k)]))