if __name__ == "__main__":
n, m = map(int, input().split())
nums = list(map(int, input().split()))
acc_sum = [0]
for item in nums:
acc_sum.append(acc_sum[-1] + item)
dp = [[float("inf")] * (1 + len(nums)) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
for j in range(1, len(nums) + 1):
for k in reversed(range(i - 1, j)):
val = max(dp[i - 1][k], acc_sum[j] - acc_sum[k])
dp[i][j] = min(val, dp[i][j])
print(dp[m][len(nums)])