from bisect import bisect_left, bisect_right from itertools import accumulate import sys input = lambda: sys.stdin.readline().rstrip("\r\n") INF = int(4e18) if __name__ == "__main__": n, k = map(int, input().split()) nums = list(map(int, input().split())) def check(mid: int) -> bool: """每段>=mid,是否能分成>=k段""" 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, lo=cur) if cur > start + n: return False return True preSum = [0] + list(accumulate(nums + nums)) left, right = 1, (sum(nums) // k) + 1 while left <= right: mid = (left + right) // 2 if check(mid): left = mid + 1 else: right = mid - 1 print(right)