n, k = map(int, input().split()) a = list(map(int, input().split())) def is_possible(mid): current_sum = 0 count = 0 for num in a: current_sum += num if current_sum >= mid: count += 1 current_sum = 0 return count >= k low = 0 high = sum(a) answer = 0 while low <= high: mid = (low + high) // 2 if mid == 0: if is_possible(1): low = mid + 1 else: answer = 0 break if is_possible(mid): answer = mid low = mid + 1 else: high = mid - 1 print(answer)