import scala.io.StdIn.{readInt,readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val input = readLine.split(" ").map(_.toInt) 
        val luggages = (1 to input(0)).foldLeft(Nil: List[Int]) { (list, v) => readInt :: list}
        println(allocation(input(1), luggages.reverse))
    }
    def allocation(k: Int, wList: List[Int]): Int = {
        // 最大積載量 = capacity の場合にトラックに荷物が乗り切るかどうか
        def inCapacity(luggages: List[Int], truck: Int, capacity: Int, curr: Int): 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(pc: Array[Int], leftPtr: Int, rightPtr: Int, currMin: Int): Int = (leftPtr + rightPtr) / 2 match {
            case center if leftPtr == rightPtr => if (center < currMin && inCapacity(wList, k, pc(center), 0)) pc(center) else currMin
            case center => inCapacity(wList, k, pc(center), 0) match {
                case true => /*println("T(" + pc(leftPtr)  + ", " + pc(rightPtr)  + ") : Array(" + center + ") = " + pc(center) + " : min = " + currMin); */binSearch(pc, leftPtr, center, pc(center))
                case false => /* println("F(" + pc(leftPtr)  + ", " + pc(rightPtr)  + ") : Array(" + center + ") = " + pc(center) + " : min = " + currMin); */binSearch(pc, center + 1, rightPtr, currMin)
            }
        }

        val maxCapa = wList.sum
        val possibleCapa = (1 to maxCapa).toArray
        binSearch(possibleCapa, 0, possibleCapa.length - 1, maxCapa)
    }
}
