def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) K = int(data[1]) A = list(map(int, data[2:2 + N])) total = sum(A) low = 0 high = total def is_possible(M): current_sum = 0 count = 0 for num in A: current_sum += num if current_sum >= M: count += 1 current_sum = 0 if count == K: return True return count == K and current_sum >= M while low < high: mid = (low + high + 1) // 2 if is_possible(mid): low = mid else: high = mid - 1 print(low) if __name__ == "__main__": main()