from bisect import bisect_left, bisect_right from itertools import accumulate n, k = map(int, input().split()) nums = list(map(int, input().split())) preSum = [0] + list(accumulate(nums + nums)) def check(mid): max_ = bisect_right(preSum, mid) for start in range(max_): if start > n: break cur = start for _ in range(k): cur = bisect_left(preSum, preSum[cur] + mid) if cur > start + n: break else: return True return False l, r = 0, (sum(nums) // k) + 1 while l <= r: mid = (l + r) // 2 if check(mid): l = mid + 1 else: r = mid - 1 print(r)