#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_4-D
=end

class Main
  def sum(f)
    f.inject(0){|acc,x| acc + x}
  end

  def ndivide(f,x,lim)
    n=f.length
    s = sum(f)
    if x>=s then
      return 1
    elsif f.max > x then
      return nil
    end
    m=0
    i=0
    while i <= n-1 do
      m += 1
      if m > lim then
        return nil
      end
      j = i
      while j <= n-1 do
        if sum(f.slice(i..j)) > x then
          j -= 1
          break
        end
        j += 1
      end
      i=j+1
    end
    m
  end
# 227994
  def initialize

    #fh=open("/home/muz/Downloads/ALDS1_4_D_in1.txt")
    #fh=open("/home/muz/Downloads/ALDS1_4_D_in2.txt")

    #fh=open("/home/muz/Downloads/ALDS1_4_D_in23.txt")
    #fh=open("/home/muz/Downloads/ALDS1_4_D_in25.txt")
    #fh=open("/home/muz/Downloads/ALDS1_4_D_in28.txt")
 fh=open("/home/muz/Downloads/ALDS1_4_D_in35.txt")
    #fh=STDIN
    f=[]
    n,m=fh.gets.chomp.split.map{|x| x.to_i}

    0.upto(n-1){|i|
      f.push(fh.gets.to_i)
    }

    total = sum(f)
    st = f.max
    ans=0
    debug=false
    #debug=true
    if debug then
      puts "m=#{m}"
      puts f.map{|x| x.to_s}.join(" ")
    end
    x2 = total
    d = (total - st)/2

    if m==1 then
      puts total
      exit
    end
    while true do
      x1 = x2 - d
      puts "x2=#{x2} x1=#{x1} d=#{d} " if debug
      q = ndivide(f,x1,m)
      puts "q=#{q}" if debug
      if q==nil then
        q=999*m
      end
      if q > m and d==1 then
        ans = x2
        break
      elsif q > m then
        d = d / 2
      else
        x2 = x1
      end
    end

    puts ans
  end
end

if $0==__FILE__ then
  Main.new()
end