import scala.io.StdIn.{readLong,readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val input = readLine.split(" ").map(_.toInt) 
        val luggages = (1 to input(0)).foldLeft(Nil: List[Long]) { (list, v) => readLong :: list}
        println(allocation(input(1), luggages.reverse))
    }
    def allocation(k: Int, wList: List[Long]): Long = {
        // 最大積載量 = capacity の場合にトラックに荷物が乗り切るかどうか
        def inCapacity(luggages: List[Long], truck: Int, capacity: Long, curr: Long): Boolean = luggages match {
            case Nil => true
            case x :: xs if (x > capacity) => false
            case x :: xs => curr + x match {
                case tmp if tmp > capacity && truck == 1 => false
                case tmp if tmp > capacity => inCapacity(xs, truck - 1, capacity, x)
                case tmp => inCapacity(xs, truck, capacity, tmp)
            }
        }
        def binSearch(min: Long, max: Long, currMin: Long): Long = (min + max) / 2 match {
            case median if min == max => if (median < currMin && inCapacity(wList, k, median, 0L)) median else currMin
            case median => inCapacity(wList, k, median, 0) match {
                case true => binSearch(min, median, median)
                case false => binSearch(median + 1, max, currMin)
            }
        }

        val maxCapa = wList.sum
        binSearch(0L, maxCapa, maxCapa)
    }
}
