import math
def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w))

def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m)
def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no
if __name__=="__main__":
    n,k = map(int,input().split(" "))
    w = []
    for i in range(n):
        w.append(int(input()))
    print(min_sufficient_load(w,k)) import math math def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w)) min_sufficient_load return check(w, k, 0, sum(w)) check(w, k, 0, sum(w)) check w k 0 sum(w) sum w w w k k def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m) check if k==1:
        return p2
     k==1 k 1 return p2 p2 if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
     p2 - p1 == 1 p2 - p1 p2 p1 1 if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
     get_trunk_No(w, p1) == k get_trunk_No(w, p1) get_trunk_No w p1 k return max(p1,max(w)) max(p1,max(w)) max p1 max(w) max w return max(p2,max(w)) max(p2,max(w)) max p2 max(w) max w m = math.ceil((p1+p2)/2) m math.ceil((p1+p2)/2) math.ceil math ceil (p1+p2)/2 p1+p2 p1 p2 2 trunk_no = get_trunk_No(w,m) trunk_no get_trunk_No(w,m) get_trunk_No w m if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m) trunk_no > k trunk_no k return check(w, k, m, p2) check(w, k, m, p2) check w k m p2 return check(w, k, p1, m) check(w, k, p1, m) check w k p1 m w w k k p1 p1 p2 p2 def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no get_trunk_No temp = 0 temp 0 trunk_no = 1 trunk_no 1 for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
     i w if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
     temp + i <= m temp + i temp i m temp += i temp i if temp == m:
                trunk_no += 1
                temp = 0
         temp == m temp m trunk_no += 1 trunk_no 1 temp = 0 temp 0 trunk_no += 1 trunk_no 1 temp = i temp i if temp==0:
        trunk_no-=1
     temp==0 temp 0 trunk_no-=1 trunk_no 1 return trunk_no trunk_no w w m m if __name__=="__main__":
    n,k = map(int,input().split(" "))
    w = []
    for i in range(n):
        w.append(int(input()))
    print(min_sufficient_load(w,k)) __name__=="__main__" __name__ "__main__" n,k = map(int,input().split(" ")) n map(int,input().split(" ")) map int input().split(" ") ().split () input split " " k w = [] w [] for i in range(n):
        w.append(int(input()))
     i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input print(min_sufficient_load(w,k)) print min_sufficient_load(w,k) min_sufficient_load w k def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w)) def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w)) min_sufficient_load w = [] [] w k = map(int,input().split(" ")) map(int,input().split(" ")) k def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m) def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m) check def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no get_trunk_No n,k = map(int,input().split(" ")) map(int,input().split(" ")) n
import math
def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w))

def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m)
def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no
if __name__=="__main__":
    n,k = map(int,input().split(" "))
    w = []
    for i in range(n):
        w.append(int(input()))
    print(min_sufficient_load(w,k))
