import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val Array(n, k) = readLine.split(" ").map(_.toInt);
        val baggage = (0 until n).map(a => readInt).toList;
        println(allocation(baggage, k));
    }
    
    def allocation(baggage: List[Int], k: Int): Int = {
        def binSearch(first: Int, last: Int, min: Int): Int = {
            print(first, last);
            val pivot = (last + first) / 2;
            if (first >= last) {
                if (check(pivot, k, baggage)) pivot else min;
            } else {
                if (check(pivot, k, baggage)) {
                    binSearch(first, pivot - 1, pivot);
                } else {
                    binSearch(pivot + 1, last, min);
                }
            }
        }
        binSearch(1, baggage.sum, Int.MaxValue);
    }
    
    def check(maxCapa: Int, trucks: Int, baggage: List[Int]): Boolean = {
        def go(restCapa: Int, restTrucks: Int, b: List[Int]): Boolean = {
            b match {
                case Nil => true;
                case weight :: restBaggage => {
                    if (weight > maxCapa) {
                        false;
                    } else {
                        if (weight <= restCapa) {
                            go(restCapa - weight, restTrucks, restBaggage);
                        } else {
                            if (restTrucks == 0) {
                                false;
                            } else {
                                go(maxCapa - weight, restTrucks - 1, restBaggage);
                            }
                        }
                    }
                }
            }
        }
        go(0, trucks, baggage);
    }
}
