fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val packages = (0 until n).map { readLine()!!.toInt() }

    fun canLoadAllPackages(p: Int): Boolean {
        var i = 0
        for (j in 0 until k) {
            var w = 0
            while (i < n && w + packages[i] <= p) {
                w += packages[i]
                i++
            }
        }
        return i == n
    }

    var l = 0
    var r = 100000 * 10000
    var m: Int

    while (r - l > 1) {
        m = (l + r) / 2
        if (canLoadAllPackages(m)) {
            r = m
        } else {
            l = m
        }
    }

    println(r)
}
