def main(): import sys input = sys.stdin.read().split() N = int(input[0]) K = int(input[1]) A = list(map(int, input[2:2+N])) total = sum(A) max_A = max(A) if K == 1: print(total) return left = 1 right = min(total // K, max_A) answer = 0 def is_possible(M): if total < K * M: return False cnt = 0 current = 0 for num in A: current += num if current >= M: cnt += 1 current = 0 return cnt >= K or (cnt >= K-1 and current >= M) while left <= right: mid = (left + right) // 2 if is_possible(mid): answer = mid left = mid + 1 else: right = mid - 1 print(answer) if __name__ == "__main__": main()