import scala.io.StdIn

object Main extends App {

  val Array(n, k) = StdIn.readLine().trim.split(' ').map(_.toInt)
  val list = (0 until n).map{ _ => StdIn.readLine().trim.toLong}.toVector
    
  def judge(p: Long): Long = {
    var i = 0
    var j = 0
    while(j < k){
      var c = 0L
      while(i < n && c + list(i) <= p){
        c += list(i)
        i += 1
      }
      j = if(i == n) k else j + 1
    }
    i
  }

  var left: Long = 0
  var right: Long = 100000 * 10000
  var mid: Long  = 0

  while(right - left > 1){
    mid = (left + right) / 2
    val v = judge(mid)
    if(v >= n){
      right = mid
    } else {
      left = mid
    }
  }

  println(right)

}
