process.stdin.resume()
process.stdin.setEncoding("utf8")

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
})

const lines = []

reader.on("line", (line) => {
  lines.push(line)
})

reader.on("close", () => {
  const [n, k] = lines[0].split(" ").map(Number)

  const boxes = Array(n)
  for (let i = 0; i < n; i++) {
    boxes[i] = lines[i + 1] - 0
  }

  // 最大積載量 P の k 台のトラックで何個の荷物を積めるか
  const check = (P) => {
    let i = 0
    for (let j = 0; j < k; j++) {
      let s = 0
      while (true) {
        s += boxes[i]
        if (s > P) break
        i++
        if (i === n) return n
      }
    }
    return i
  }

  const solve = () => {
    let left = 0
    let right = 100000 * 10000
    let mid
    while (right - left > 1) {
      mid = Math.floor((left + right) / 2)
      let v = check(mid)
      if (v >= n) right = mid
      else left = mid
    }
    return right
  }

  console.log(solve())
})

